51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package taskgraph
|
|
|
|
import "fmt"
|
|
|
|
type Status string
|
|
|
|
const (
|
|
StatusDraft Status = "draft"
|
|
StatusActive Status = "active"
|
|
StatusSuperseded Status = "superseded"
|
|
StatusCancelled Status = "cancelled"
|
|
)
|
|
|
|
type Record struct {
|
|
ID string `json:"id"`
|
|
TopicID string `json:"topic_id"`
|
|
Version int `json:"version"`
|
|
Status Status `json:"status"`
|
|
PlanJSON string `json:"plan_json"`
|
|
PlanSummaryMarkdown string `json:"plan_summary_markdown"`
|
|
CreatedByRoleName string `json:"created_by_role_name"`
|
|
CreatedAt string `json:"created_at"`
|
|
ConfirmedAt string `json:"confirmed_at,omitempty"`
|
|
SupersedesGraphVersionID string `json:"supersedes_graph_version_id,omitempty"`
|
|
}
|
|
|
|
func ValidateStatus(value Status) error {
|
|
switch value {
|
|
case StatusDraft, StatusActive, StatusSuperseded, StatusCancelled:
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("invalid task graph status %q", value)
|
|
}
|
|
}
|
|
|
|
func (r Record) Validate() error {
|
|
if r.TopicID == "" {
|
|
return fmt.Errorf("topic id is required")
|
|
}
|
|
if r.Version <= 0 {
|
|
return fmt.Errorf("version must be greater than zero")
|
|
}
|
|
if r.PlanJSON == "" {
|
|
return fmt.Errorf("plan json is required")
|
|
}
|
|
if r.CreatedByRoleName == "" {
|
|
return fmt.Errorf("created by role is required")
|
|
}
|
|
return ValidateStatus(r.Status)
|
|
}
|