{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://libesys.org/schemas/a2c/task-draft.schema.json",
  "title": "A2C task draft",
  "description": "One proposed task from epic decomposition (TaskDraftItem) or a single-task JSON import for plan create-task --from-task-json.",
  "oneOf": [
    { "$ref": "#/$defs/taskDraftItem" },
    { "$ref": "#/$defs/taskDraftImport" }
  ],
  "$defs": {
    "profile": {
      "type": "string",
      "enum": ["feature-minimal", "feature-expanded", "bug"],
      "description": "Task body profile from profiles/task-body/; defaults to feature-minimal when sections are used without profile."
    },
    "sections": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "type": "string",
        "minLength": 1
      },
      "description": "Section-keyed markdown fragments composed into a body using the selected profile."
    },
    "bodyContent": {
      "anyOf": [
        { "required": ["body"] },
        { "required": ["sections"] }
      ]
    },
    "taskDraftItem": {
      "title": "Decomposition task draft",
      "description": "Canonical shape validated by TaskDraftItem after epic decomposition.",
      "type": "object",
      "additionalProperties": true,
      "allOf": [
        { "required": ["title", "epic_id"] },
        { "$ref": "#/$defs/bodyContent" }
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Optional task id; allocated at apply when omitted."
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "type": "string",
          "enum": ["todo", "in_progress", "done", "blocked"],
          "default": "todo"
        },
        "epic_id": {
          "type": "string",
          "minLength": 1,
          "description": "Epic this task belongs to."
        },
        "profile": {
          "$ref": "#/$defs/profile"
        },
        "body": {
          "type": "string",
          "minLength": 1,
          "description": "Monolithic markdown body. Section requirements follow profiles/task-body/ (feature-minimal by default)."
        },
        "sections": {
          "$ref": "#/$defs/sections"
        },
        "rationale": {
          "type": ["string", "null"],
          "description": "Optional decomposition note; ignored by single-task intake import."
        }
      }
    },
    "taskDraftImport": {
      "title": "Single-task JSON import",
      "description": "Relaxed variant accepted by plan create-task --from-task-json. Final task id is allocated at apply draft-task when id is omitted; use --epic when epic_id is omitted.",
      "type": "object",
      "additionalProperties": true,
      "allOf": [
        { "required": ["title"] },
        { "$ref": "#/$defs/bodyContent" }
      ],
      "not": {
        "required": ["tasks"]
      },
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Optional id hint; when set, used as the final planning/tasks id at apply."
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "type": "string",
          "enum": ["todo", "in_progress", "done", "blocked"],
          "default": "todo"
        },
        "epic_id": {
          "type": "string",
          "minLength": 1,
          "description": "Optional epic link; CLI --epic overrides when both are set."
        },
        "profile": {
          "$ref": "#/$defs/profile"
        },
        "body": {
          "type": "string",
          "minLength": 1,
          "description": "Monolithic markdown body. Section requirements follow profiles/task-body/."
        },
        "sections": {
          "$ref": "#/$defs/sections"
        },
        "rationale": {
          "type": ["string", "null"],
          "description": "Ignored by import; stored only if present in source JSON."
        },
        "tasks": false
      }
    }
  }
}
