{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://consentocracy.com/schemas/consentocracy-charter.schema.json",
  "title": "Consentocracy Constitutional Charter Schema",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "artifact_id",
    "name",
    "version",
    "layer",
    "type",
    "status",
    "description",
    "constitutional_statement",
    "capabilities",
    "quantum_invariants",
    "axioms",
    "definitions",
    "relational_units",
    "fractal_consent_stack",
    "implementation_requirements",
    "failure_modes",
    "repair_paths",
    "nonclaims",
    "conformance",
    "change_control"
  ],
  "properties": {
    "$schema": {
      "type": "string"
    },
    "@context": {
      "type": "string"
    },
    "id": {
      "const": "CO-CHARTER-001"
    },
    "artifact_id": {
      "type": "string"
    },
    "name": {
      "type": "string"
    },
    "version": {
      "type": "string"
    },
    "release_date": {
      "type": "string",
      "format": "date"
    },
    "canonical_url": {
      "type": "string",
      "format": "uri"
    },
    "layer": {
      "const": "L3"
    },
    "type": {
      "const": "constitutional_charter"
    },
    "status": {
      "enum": [
        "draft",
        "canonical",
        "superseded"
      ]
    },
    "license": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "constitutional_statement": {
      "type": "string"
    },
    "capabilities": {
      "type": "object",
      "required": [
        "operates_value_exchange",
        "defines_conditions_for_consentful_exchange",
        "issues_tokens",
        "provides_wallet_services",
        "certifies_implementations",
        "publishes_constitutional_requirements"
      ],
      "properties": {
        "operates_value_exchange": {
          "type": "boolean"
        },
        "defines_conditions_for_consentful_exchange": {
          "type": "boolean"
        },
        "issues_tokens": {
          "type": "boolean"
        },
        "provides_wallet_services": {
          "type": "boolean"
        },
        "certifies_implementations": {
          "type": "boolean"
        },
        "publishes_constitutional_requirements": {
          "type": "boolean"
        },
        "publishes_conformance_schema": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    },
    "epistemic_classes": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "uniqueItems": true
    },
    "quantum_invariants": {
      "type": "object",
      "required": [
        "manifest",
        "manifest_version",
        "canonical_spine",
        "layer0_primitives_version",
        "layer1_composites_version",
        "relationship"
      ],
      "properties": {
        "manifest": {
          "type": "string",
          "format": "uri"
        },
        "manifest_version": {
          "type": "string"
        },
        "canonical_spine": {
          "type": "string",
          "format": "uri"
        },
        "layer0_primitives_version": {
          "type": "string"
        },
        "layer1_composites_version": {
          "type": "string"
        },
        "relationship": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "axioms": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/axiom"
      }
    },
    "definitions": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/definition"
      }
    },
    "relational_units": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/unit"
      }
    },
    "fractal_consent_stack": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/stackLayer"
      }
    },
    "implementation_requirements": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/requirement"
      }
    },
    "failure_modes": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/failure"
      }
    },
    "repair_paths": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/repair"
      }
    },
    "nonclaims": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string"
      }
    },
    "conformance": {
      "type": "object"
    },
    "change_control": {
      "type": "object"
    }
  },
  "$defs": {
    "baseNode": {
      "type": "object",
      "required": [
        "id",
        "type",
        "title"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^CO-[A-Z]+-[0-9]{3}$"
        },
        "type": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "status": {
          "type": "string"
        },
        "layer": {
          "type": "string"
        },
        "qi_grounding": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[PC][0-9]+$"
          },
          "uniqueItems": true
        }
      },
      "additionalProperties": true
    },
    "axiom": {
      "allOf": [
        {
          "$ref": "#/$defs/baseNode"
        },
        {
          "type": "object",
          "required": [
            "statement",
            "normative_force",
            "scope",
            "not_equivalent_to"
          ]
        }
      ]
    },
    "definition": {
      "allOf": [
        {
          "$ref": "#/$defs/baseNode"
        },
        {
          "type": "object",
          "required": [
            "definition",
            "not_equivalent_to"
          ]
        }
      ]
    },
    "unit": {
      "allOf": [
        {
          "$ref": "#/$defs/baseNode"
        },
        {
          "type": "object",
          "required": [
            "definition",
            "minimum_components"
          ]
        }
      ]
    },
    "stackLayer": {
      "allOf": [
        {
          "$ref": "#/$defs/baseNode"
        },
        {
          "type": "object",
          "required": [
            "order",
            "statement"
          ]
        }
      ]
    },
    "requirement": {
      "allOf": [
        {
          "$ref": "#/$defs/baseNode"
        },
        {
          "type": "object",
          "required": [
            "statement",
            "normative_force"
          ]
        }
      ]
    },
    "failure": {
      "allOf": [
        {
          "$ref": "#/$defs/baseNode"
        },
        {
          "type": "object",
          "required": [
            "description"
          ]
        }
      ]
    },
    "repair": {
      "allOf": [
        {
          "$ref": "#/$defs/baseNode"
        },
        {
          "type": "object",
          "required": [
            "description"
          ]
        }
      ]
    }
  }
}
