Validate reports whether the task record contains the canonical persisted shape.
()
| 410 | |
| 411 | // Validate reports whether the task record contains the canonical persisted shape. |
| 412 | func (t Task) Validate() error { |
| 413 | if strings.TrimSpace(t.ID) == "" { |
| 414 | return fmt.Errorf("%w: task.id is required", ErrValidation) |
| 415 | } |
| 416 | if err := ValidateScopeBinding(t.Scope, t.WorkspaceID, "task", "workspace_id"); err != nil { |
| 417 | return err |
| 418 | } |
| 419 | if strings.TrimSpace(t.ParentTaskID) != "" && strings.TrimSpace(t.ParentTaskID) == strings.TrimSpace(t.ID) { |
| 420 | return fmt.Errorf("%w: task.parent_task_id cannot equal task.id", ErrValidation) |
| 421 | } |
| 422 | if strings.TrimSpace(t.Title) == "" { |
| 423 | return fmt.Errorf("%w: task.title is required", ErrValidation) |
| 424 | } |
| 425 | if err := t.Status.Validate("task.status"); err != nil { |
| 426 | return err |
| 427 | } |
| 428 | if t.Status.Normalize() == TaskStatusDraft && !t.ClosedAt.IsZero() { |
| 429 | return fmt.Errorf("%w: task.closed_at must be empty while task.status is %q", ErrValidation, TaskStatusDraft) |
| 430 | } |
| 431 | if err := normalizePriorityOrDefault(t.Priority).Validate("task.priority"); err != nil { |
| 432 | return err |
| 433 | } |
| 434 | if err := validateTaskMaxAttempts(t.MaxAttempts, "task.max_attempts", true); err != nil { |
| 435 | return err |
| 436 | } |
| 437 | approvalPolicy := normalizeApprovalPolicyOrDefault(t.ApprovalPolicy) |
| 438 | if err := approvalPolicy.Validate("task.approval_policy"); err != nil { |
| 439 | return err |
| 440 | } |
| 441 | approvalState := normalizeApprovalStateOrDefault(approvalPolicy, t.ApprovalState) |
| 442 | if err := approvalState.Validate("task.approval_state"); err != nil { |
| 443 | return err |
| 444 | } |
| 445 | if err := ValidateApprovalSemantics(approvalPolicy, approvalState, "task"); err != nil { |
| 446 | return err |
| 447 | } |
| 448 | if err := t.CreatedBy.Validate("task.created_by"); err != nil { |
| 449 | return err |
| 450 | } |
| 451 | if err := validateNeedsAttention(t.NeedsAttention); err != nil { |
| 452 | return err |
| 453 | } |
| 454 | if err := t.Origin.Validate("task.origin"); err != nil { |
| 455 | return err |
| 456 | } |
| 457 | if t.Owner != nil { |
| 458 | if err := t.Owner.Validate("task.owner"); err != nil { |
| 459 | return err |
| 460 | } |
| 461 | } |
| 462 | if err := ValidateMetadataSize(t.Metadata, "task.metadata"); err != nil { |
| 463 | return err |
| 464 | } |
| 465 | return nil |
| 466 | } |
| 467 | |
| 468 | func validateNeedsAttention(attention *NeedsAttention) error { |
| 469 | if attention == nil { |
no test coverage detected