{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "provenancecode.decision.v1",
  "title": "Decision Evidence Object (DEO v1.0)",
  "description": "Schema for ProvenanceCode DEO v1.0 decision records",
  "type": "object",
  "required": [
    "schema",
    "id",
    "title",
    "version",
    "lifecycle",
    "timestamps",
    "actors",
    "outcome",
    "rationale",
    "risk"
  ],
  "properties": {
    "schema": {
      "type": "string",
      "const": "provenancecode.decision.v1",
      "description": "Schema identifier"
    },
    "id": {
      "type": "string",
      "pattern": "^(DEC-[A-Z0-9]{2,6}(-[A-Z0-9]{2,6})?-[0-9]{7}|DEC-[0-9]{6})$",
      "description": "Unique decision identifier"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "description": "Brief title of the decision"
    },
    "version": {
      "type": "integer",
      "minimum": 1,
      "description": "Record version, starting at 1"
    },
    "lifecycle": {
      "type": "object",
      "required": ["state"],
      "properties": {
        "state": {
          "type": "string",
          "enum": ["draft", "proposed", "accepted", "rejected", "superseded"],
          "description": "Current lifecycle state"
        },
        "supersedes": {
          "type": ["string", "null"],
          "description": "ID of the decision this supersedes"
        },
        "superseded_by": {
          "type": ["string", "null"],
          "description": "ID of the decision that superseded this one"
        }
      },
      "additionalProperties": false
    },
    "timestamps": {
      "type": "object",
      "required": ["created_at"],
      "properties": {
        "created_at": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 timestamp of creation"
        },
        "accepted_at": {
          "type": ["string", "null"],
          "format": "date-time",
          "description": "ISO 8601 timestamp when accepted"
        },
        "updated_at": {
          "type": ["string", "null"],
          "format": "date-time",
          "description": "ISO 8601 timestamp of last update"
        },
        "expires_at": {
          "type": ["string", "null"],
          "format": "date-time",
          "description": "ISO 8601 timestamp when this decision expires"
        }
      },
      "additionalProperties": false
    },
    "actors": {
      "type": "object",
      "required": ["author"],
      "properties": {
        "author": {
          "type": "string",
          "minLength": 1,
          "description": "Decision author (required)"
        },
        "approver": {
          "type": "string",
          "description": "Who approved this decision"
        },
        "bot": {
          "type": "string",
          "description": "AI agent that created or assisted (e.g. cursor-ai, kiro, claude-code)"
        },
        "reviewers": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Reviewers of this decision"
        }
      },
      "additionalProperties": false
    },
    "outcome": {
      "type": "string",
      "minLength": 1,
      "description": "The decision outcome — what was decided"
    },
    "rationale": {
      "type": "string",
      "description": "Why this decision was made"
    },
    "risk": {
      "type": "object",
      "required": ["level"],
      "properties": {
        "level": {
          "type": "string",
          "enum": ["low", "medium", "high", "critical"],
          "description": "Risk level"
        },
        "description": {
          "type": "string",
          "description": "Description of the risk"
        },
        "acceptance": {
          "type": "string",
          "description": "Risk acceptance rationale"
        },
        "mitigations": {
          "type": "array",
          "items": { "type": "string" },
          "description": "List of mitigations"
        }
      },
      "additionalProperties": false
    },
    "problem": {
      "type": "string",
      "description": "The problem being solved (optional)"
    },
    "options": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Options considered"
    },
    "consequences": {
      "type": "string",
      "description": "Expected consequences and implications"
    },
    "context": {
      "type": "object",
      "properties": {
        "jira_key": { "type": "string" },
        "repo": { "type": "string" },
        "component": { "type": "string" },
        "links": {
          "type": "array",
          "items": { "type": "string" }
        }
      },
      "additionalProperties": false,
      "description": "Project context metadata"
    },
    "scope": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Scope of impact"
    },
    "tags": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Tags for categorization"
    },
    "links": {
      "type": "object",
      "properties": {
        "pr": { "type": "array", "items": { "type": "string" } },
        "issues": { "type": "array", "items": { "type": "string" } },
        "specs": { "type": "array", "items": { "type": "string" } },
        "decisions": { "type": "array", "items": { "type": "string" } },
        "risks": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": false,
      "description": "Related links grouped by type"
    },
    "integrity": {
      "type": "object",
      "properties": {
        "receipt_path": { "type": "string" },
        "commit_sha": { "type": "string" },
        "prov_path": { "type": "string" }
      },
      "additionalProperties": false
    },
    "attestations": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["type"],
        "properties": {
          "type": { "type": "string" },
          "manifest_path": { "type": "string" }
        }
      }
    },
    "metadata": {
      "type": "object",
      "description": "Arbitrary additional metadata"
    }
  },
  "additionalProperties": false
}
