{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "provenancecode.decision.v2",
  "title": "ProvenanceCode Decision Record (v2.0)",
  "description": "Schema for ProvenanceCode v2.0 decision records",
  "type": "object",
  "required": [
    "schema",
    "decision_id",
    "title",
    "status"
  ],
  "properties": {
    "schema": {
      "type": "string",
      "const": "provenancecode.decision.v2",
      "description": "Schema identifier"
    },
    "decision_id": {
      "type": "string",
      "pattern": "^DEC-[A-Z0-9]{2,4}-[A-Z0-9]{2,4}-[0-9]{6}$",
      "description": "Unique decision identifier (format: DEC-{PROJECT}-{SUBPROJECT}-{SEQ6})"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "description": "Brief title of the decision"
    },
    "status": {
      "type": "string",
      "enum": ["draft", "proposed", "accepted", "rejected", "deprecated", "superseded"],
      "description": "Current status of the decision"
    },
    "project": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string",
          "pattern": "^[A-Z0-9]{2,4}$",
          "description": "Project code (2-4 uppercase chars)"
        },
        "name": {
          "type": "string",
          "description": "Project name"
        },
        "jiraProject": {
          "type": "string",
          "description": "Jira project key"
        }
      }
    },
    "subproject": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string",
          "pattern": "^[A-Z0-9]{2,4}$",
          "description": "Subproject code (2-4 uppercase chars)"
        },
        "name": {
          "type": "string",
          "description": "Subproject name"
        },
        "workspace": {
          "type": "string",
          "description": "Workspace path in monorepo"
        },
        "jiraComponent": {
          "type": "string",
          "description": "Jira component name"
        }
      }
    },
    "context": {
      "oneOf": [
        {
          "type": "string",
          "description": "Background context (v1.0 compatibility)"
        },
        {
          "type": "object",
          "properties": {
            "problem": {
              "type": "string",
              "description": "Problem being solved"
            },
            "constraints": {
              "type": "array",
              "items": { "type": "string" },
              "description": "Technical constraints"
            }
          }
        }
      ]
    },
    "decision": {
      "type": "string",
      "minLength": 1,
      "description": "The decision that was made"
    },
    "consequences": {
      "type": "string",
      "description": "Expected consequences and implications"
    },
    "risk": {
      "type": "string",
      "description": "Risk assessment or mitigation notes"
    },
    "links": {
      "oneOf": [
        {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["type", "url"],
            "properties": {
              "type": {
                "type": "string",
                "enum": ["pr", "issue", "doc", "decision", "risk", "other"]
              },
              "url": {
                "type": "string",
                "format": "uri"
              },
              "title": {
                "type": "string"
              }
            }
          }
        },
        {
          "type": "object",
          "properties": {
            "pr": {
              "type": "string",
              "format": "uri",
              "description": "Pull request URL"
            },
            "jira": {
              "type": "string",
              "format": "uri",
              "description": "Jira ticket URL"
            }
          }
        }
      ],
      "description": "Related links (PRs, issues, docs, other decisions)"
    },
    "timestamps": {
      "type": "object",
      "properties": {
        "created_at": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 timestamp of creation"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 timestamp of last update"
        }
      }
    },
    "authors": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Decision authors or contributors"
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Tags for categorization"
    }
  },
  "additionalProperties": true
}

