# Schema for agent task assignment
# Used by AgentCoordinator for internal task assignment validation
{
  schema_name = "task_assignment",

  description = "Validates agent task assignment requests from AgentCoordinator",

  fields = {
    # Agent role - must match registered roles
    role
      | String
      | doc "Agent role for task execution"
      | std.string.NonEmpty
      | std.enum.TaggedUnion
      | [| 'developer, 'reviewer, 'architect, 'tester, 'documenter, 'devops, 'monitor, 'security |],

    # Task title
    title
      | String
      | doc "Task title (3-500 chars)"
      | std.string.NonEmpty
      | std.string.length.min 3
      | std.string.length.max 500,

    # Task description
    description
      | String
      | doc "Detailed task description"
      | default = "",

    # Task context (JSON string)
    context
      | String
      | doc "JSON context for task execution"
      | default = "{}",

    # Priority score (0-100)
    priority
      | Number
      | doc "Task priority score (0=lowest, 100=highest)"
      | std.number.between 0 100
      | default = 50,

    # Optional deadline (ISO 8601 datetime string)
    deadline
      | String
      | doc "Task deadline (ISO 8601 format, optional)"
      | default = "",
  },

  # Custom validation contracts
  contracts = {
    # Title must not be only whitespace
    title_not_whitespace = fun fields =>
      std.string.trim fields.title != "",

    # Context must be valid JSON
    context_valid_json = fun fields =>
      if fields.context == "{}" then
        true
      else
        std.string.is_match "^[\\{\\[]" fields.context,

    # If deadline is provided, must match ISO 8601 pattern
    deadline_iso8601 = fun fields =>
      if fields.deadline == "" then
        true
      else
        std.string.is_match "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}" fields.deadline,
  },
}
