52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package domain
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type EnvironmentStatus string
|
|
|
|
const (
|
|
EnvironmentStatusCreating EnvironmentStatus = "CREATING"
|
|
EnvironmentStatusActive EnvironmentStatus = "ACTIVE"
|
|
EnvironmentStatusDeleting EnvironmentStatus = "DELETING"
|
|
EnvironmentStatusDeleted EnvironmentStatus = "DELETED"
|
|
EnvironmentStatusFailed EnvironmentStatus = "FAILED"
|
|
)
|
|
|
|
type Environment struct {
|
|
ID string
|
|
Name string
|
|
Status EnvironmentStatus
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
func (e Environment) Validate() error {
|
|
if strings.TrimSpace(e.ID) == "" {
|
|
return fmt.Errorf("%w: environment id is required", ErrInvalidArgument)
|
|
}
|
|
if strings.TrimSpace(e.Name) == "" {
|
|
return fmt.Errorf("%w: environment name is required", ErrInvalidArgument)
|
|
}
|
|
if !e.Status.Valid() {
|
|
return fmt.Errorf("%w: environment status %q", ErrInvalidStatus, e.Status)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s EnvironmentStatus) Valid() bool {
|
|
switch s {
|
|
case EnvironmentStatusCreating,
|
|
EnvironmentStatusActive,
|
|
EnvironmentStatusDeleting,
|
|
EnvironmentStatusDeleted,
|
|
EnvironmentStatusFailed:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|