{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://altheia.local/schemas/altheia_archetype_ownership_requirements_1.0.schema.json",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "requirements_id",
    "requirements_version",
    "status",
    "catalog_reference",
    "taxonomy_reference",
    "requirements",
    "governance"
  ],
  "properties": {
    "schema_version": {
      "const": "altheia_archetype_ownership_requirements_1.0"
    },
    "requirements_id": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
    },
    "requirements_version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$"
    },
    "status": {
      "enum": [
        "draft",
        "approved"
      ]
    },
    "catalog_reference": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "sector_id",
        "catalog_id",
        "catalog_version",
        "catalog_hash"
      ],
      "properties": {
        "sector_id": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
        },
        "catalog_id": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
        },
        "catalog_version": {
          "type": "string",
          "pattern": "^\\d+\\.\\d+\\.\\d+$"
        },
        "catalog_hash": {
          "type": "string",
          "pattern": "^fnv1a-[a-f0-9]{8}$"
        }
      }
    },
    "taxonomy_reference": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "taxonomy_version",
        "taxonomy_hash"
      ],
      "properties": {
        "taxonomy_version": {
          "type": "string",
          "minLength": 1
        },
        "taxonomy_hash": {
          "type": "string",
          "pattern": "^fnv1a-[a-f0-9]{8}$"
        }
      }
    },
    "requirements": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "archetype_id",
          "mode",
          "scope",
          "all_of",
          "any_of",
          "none_of",
          "minimum_distinct_providers",
          "source_statuses",
          "required_facts",
          "minimum_behavioral_evidence",
          "review_status",
          "rationale"
        ],
        "properties": {
          "archetype_id": {
            "type": "string",
            "minLength": 1
          },
          "mode": {
            "enum": [
              "unreviewed",
              "independent",
              "conditional"
            ]
          },
          "scope": {
            "enum": [
              "overall",
              "focal"
            ]
          },
          "all_of": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
            },
            "minItems": 0,
            "uniqueItems": true
          },
          "any_of": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
            },
            "minItems": 0,
            "uniqueItems": true
          },
          "none_of": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
            },
            "minItems": 0,
            "uniqueItems": true
          },
          "minimum_distinct_providers": {
            "type": "integer",
            "minimum": 0
          },
          "source_statuses": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
            },
            "minItems": 0,
            "uniqueItems": true
          },
          "required_facts": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "field_path",
                "operator",
                "value"
              ],
              "properties": {
                "field_path": {
                  "type": "string",
                  "pattern": "^/(base_data|context_memory|sector_data/profile_fields)/.+"
                },
                "operator": {
                  "enum": [
                    "eq",
                    "neq",
                    "gt",
                    "gte",
                    "lt",
                    "lte",
                    "in"
                  ]
                },
                "value": {
                  "type": [
                    "string",
                    "number",
                    "boolean",
                    "null",
                    "array"
                  ],
                  "items": {
                    "type": [
                      "string",
                      "number",
                      "boolean",
                      "null"
                    ]
                  }
                }
              }
            },
            "minItems": 0,
            "uniqueItems": true
          },
          "minimum_behavioral_evidence": {
            "type": "integer",
            "minimum": 2,
            "maximum": 10
          },
          "review_status": {
            "enum": [
              "pending",
              "approved"
            ]
          },
          "rationale": {
            "type": "string",
            "minLength": 20
          }
        }
      },
      "minItems": 1,
      "uniqueItems": true
    },
    "governance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "sources",
        "reviewed_by",
        "reviewed_at",
        "rationale"
      ],
      "properties": {
        "sources": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "reviewed_by": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1
        },
        "reviewed_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "rationale": {
          "type": "string",
          "minLength": 20
        }
      }
    }
  }
}
