rwadurian/backend/mpc-system/services/account/domain/value_objects/account_status.go

109 lines
2.7 KiB
Go

package value_objects
// AccountStatus represents the status of an account
type AccountStatus string
const (
AccountStatusActive AccountStatus = "active"
AccountStatusSuspended AccountStatus = "suspended"
AccountStatusLocked AccountStatus = "locked"
AccountStatusRecovering AccountStatus = "recovering"
)
// String returns the string representation
func (s AccountStatus) String() string {
return string(s)
}
// IsValid checks if the status is valid
func (s AccountStatus) IsValid() bool {
switch s {
case AccountStatusActive, AccountStatusSuspended, AccountStatusLocked, AccountStatusRecovering:
return true
default:
return false
}
}
// CanLogin checks if the account can login with this status
func (s AccountStatus) CanLogin() bool {
return s == AccountStatusActive
}
// CanInitiateRecovery checks if recovery can be initiated
func (s AccountStatus) CanInitiateRecovery() bool {
return s == AccountStatusActive || s == AccountStatusLocked
}
// ShareType represents the type of key share
type ShareType string
const (
ShareTypeUserDevice ShareType = "user_device"
ShareTypeServer ShareType = "server"
ShareTypeRecovery ShareType = "recovery"
)
// String returns the string representation
func (st ShareType) String() string {
return string(st)
}
// IsValid checks if the share type is valid
func (st ShareType) IsValid() bool {
switch st {
case ShareTypeUserDevice, ShareTypeServer, ShareTypeRecovery:
return true
default:
return false
}
}
// RecoveryType represents the type of account recovery
type RecoveryType string
const (
RecoveryTypeDeviceLost RecoveryType = "device_lost"
RecoveryTypeShareRotation RecoveryType = "share_rotation"
)
// String returns the string representation
func (rt RecoveryType) String() string {
return string(rt)
}
// IsValid checks if the recovery type is valid
func (rt RecoveryType) IsValid() bool {
switch rt {
case RecoveryTypeDeviceLost, RecoveryTypeShareRotation:
return true
default:
return false
}
}
// RecoveryStatus represents the status of a recovery session
type RecoveryStatus string
const (
RecoveryStatusRequested RecoveryStatus = "requested"
RecoveryStatusInProgress RecoveryStatus = "in_progress"
RecoveryStatusCompleted RecoveryStatus = "completed"
RecoveryStatusFailed RecoveryStatus = "failed"
)
// String returns the string representation
func (rs RecoveryStatus) String() string {
return string(rs)
}
// IsValid checks if the recovery status is valid
func (rs RecoveryStatus) IsValid() bool {
switch rs {
case RecoveryStatusRequested, RecoveryStatusInProgress, RecoveryStatusCompleted, RecoveryStatusFailed:
return true
default:
return false
}
}