package domain import ( "fmt" "strings" "time" ) type WorkloadStatus string const ( WorkloadStatusPending WorkloadStatus = "PENDING" WorkloadStatusDeploying WorkloadStatus = "DEPLOYING" WorkloadStatusRunning WorkloadStatus = "RUNNING" WorkloadStatusFailed WorkloadStatus = "FAILED" ) type Workload struct { ID string EnvironmentID string Name string Image string Status WorkloadStatus CreatedAt time.Time UpdatedAt time.Time } func (w Workload) Validate() error { if strings.TrimSpace(w.ID) == "" { return fmt.Errorf("%w: workload id is required", ErrInvalidArgument) } if strings.TrimSpace(w.EnvironmentID) == "" { return fmt.Errorf("%w: environment id is required", ErrInvalidArgument) } if strings.TrimSpace(w.Name) == "" { return fmt.Errorf("%w: workload name is required", ErrInvalidArgument) } if strings.TrimSpace(w.Image) == "" { return fmt.Errorf("%w: workload image is required", ErrInvalidArgument) } if !w.Status.Valid() { return fmt.Errorf("%w: workload status %q", ErrInvalidStatus, w.Status) } return nil } func (s WorkloadStatus) Valid() bool { switch s { case WorkloadStatusPending, WorkloadStatusDeploying, WorkloadStatusRunning, WorkloadStatusFailed: return true default: return false } }