{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://aiep.dev/schemas/aiep.canonical.schema.v2.0.0.json",
    "title": "AIEP Canonical Schema v2.0.0",
    "description": "Canonical validation schema for all AIEP record types. Validates by record_type discriminator using anyOf sub-schemas.",
    "type": "object",
    "anyOf": [
        {
            "$ref": "#/$defs/AiepMetadata"
        },
        {
            "$ref": "#/$defs/AiepWellKnownIndex"
        },
        {
            "$ref": "#/$defs/AiepCertificate"
        },
        {
            "$ref": "#/$defs/AiepAuditEvent"
        },
        {
            "$ref": "#/$defs/AiepInnovationLedgerEntry"
        },
        {
            "$ref": "#/$defs/AiepGenericRecord"
        }
    ],
    "$defs": {
        "AiepMetadata": {
            "title": "AIEP Metadata Record",
            "required": [
                "record_type",
                "aiep_protocol",
                "aiep_name",
                "aiep_spec_version",
                "publisher",
                "open_use_policy",
                "certification"
            ],
            "properties": {
                "record_type": {
                    "const": "AIEP_METADATA"
                },
                "aiep_protocol": {
                    "const": "AIEP"
                },
                "aiep_name": {
                    "type": "string",
                    "minLength": 1
                },
                "aiep_spec_version": {
                    "type": "string",
                    "minLength": 1
                },
                "publisher": {
                    "type": "object",
                    "required": [
                        "name",
                        "domain"
                    ],
                    "properties": {
                        "name": {
                            "type": "string"
                        },
                        "domain": {
                            "type": "string"
                        },
                        "contact_path": {
                            "type": "string"
                        },
                        "email": {
                            "type": "string"
                        }
                    }
                },
                "open_use_policy": {
                    "type": "object",
                    "required": [
                        "open_use_permitted"
                    ],
                    "properties": {
                        "open_use_permitted": {
                            "type": "boolean"
                        },
                        "statement": {
                            "type": "string"
                        }
                    }
                },
                "certification": {
                    "type": "object",
                    "required": [
                        "claims_aiep_certified"
                    ],
                    "properties": {
                        "claims_aiep_certified": {
                            "type": "boolean"
                        },
                        "certificate_id": {
                            "type": "string"
                        },
                        "certificate_url": {
                            "type": "string"
                        },
                        "issuer": {
                            "type": "string"
                        },
                        "issuer_public_key": {
                            "type": "string"
                        },
                        "signature": {
                            "type": "string"
                        }
                    }
                },
                "governing_law": {
                    "type": "object",
                    "properties": {
                        "jurisdiction": {
                            "type": "string"
                        },
                        "statement": {
                            "type": "string"
                        }
                    }
                }
            },
            "additionalProperties": true
        },
        "AiepWellKnownIndex": {
            "title": "AIEP Well-Known Index Record",
            "required": [
                "record_type",
                "aiep_protocol",
                "aiep_name",
                "aiep_spec_version",
                "hub",
                "policy"
            ],
            "properties": {
                "record_type": {
                    "const": "AIEP_WELL_KNOWN_INDEX"
                },
                "aiep_protocol": {
                    "const": "AIEP"
                },
                "aiep_name": {
                    "type": "string",
                    "minLength": 1
                },
                "aiep_spec_version": {
                    "type": "string",
                    "minLength": 1
                },
                "hub": {
                    "type": "object",
                    "required": [
                        "name",
                        "machine_base_path"
                    ],
                    "properties": {
                        "name": {
                            "type": "string"
                        },
                        "description": {
                            "type": "string"
                        },
                        "machine_base_path": {
                            "type": "string"
                        }
                    }
                },
                "policy": {
                    "type": "object",
                    "required": [
                        "open_use_permitted"
                    ],
                    "properties": {
                        "open_use_permitted": {
                            "type": "boolean"
                        },
                        "note": {
                            "type": "string"
                        }
                    }
                },
                "endpoints": {
                    "type": "object"
                },
                "surfaces": {
                    "type": "object"
                }
            },
            "additionalProperties": true
        },
        "AiepCertificate": {
            "title": "AIEP Certificate Record",
            "required": [
                "certificate_id",
                "issuer_id",
                "subject",
                "issued_at_utc",
                "policy_id",
                "signature"
            ],
            "properties": {
                "certificate_id": {
                    "type": "string",
                    "minLength": 1
                },
                "issuer_id": {
                    "type": "string",
                    "minLength": 1
                },
                "subject": {
                    "type": "object",
                    "required": [
                        "domain"
                    ],
                    "properties": {
                        "domain": {
                            "type": "string",
                            "minLength": 1
                        }
                    }
                },
                "issued_at_utc": {
                    "type": "string"
                },
                "expires_at_utc": {
                    "type": "string"
                },
                "policy_id": {
                    "type": "string",
                    "minLength": 1
                },
                "artefacts": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                },
                "signature": {
                    "type": "string",
                    "minLength": 1
                },
                "issuer_public_key_url": {
                    "type": "string"
                }
            },
            "additionalProperties": true
        },
        "AiepAuditEvent": {
            "title": "AIEP Audit Event Record",
            "required": [
                "event_id",
                "timestamp_utc",
                "event_type",
                "prev_hash",
                "event_hash"
            ],
            "properties": {
                "event_id": {
                    "type": "string",
                    "minLength": 1
                },
                "timestamp_utc": {
                    "type": "string",
                    "minLength": 1
                },
                "event_type": {
                    "type": "string",
                    "minLength": 1
                },
                "file_id": {
                    "type": "string"
                },
                "request_ip_hash": {
                    "type": "string"
                },
                "user_agent_hash": {
                    "type": "string"
                },
                "prev_hash": {
                    "type": "string"
                },
                "event_hash": {
                    "type": "string",
                    "minLength": 1
                }
            },
            "additionalProperties": true
        },
        "AiepInnovationLedgerEntry": {
            "title": "AIEP Innovation Ledger Entry",
            "required": [
                "record_type",
                "record_id",
                "title",
                "originator",
                "created_utc",
                "visibility"
            ],
            "properties": {
                "record_type": {
                    "const": "AIEP_INNOVATION_LEDGER_ENTRY"
                },
                "record_id": {
                    "type": "string",
                    "minLength": 1
                },
                "title": {
                    "type": "string",
                    "minLength": 1
                },
                "originator": {
                    "type": "string",
                    "minLength": 1
                },
                "created_utc": {
                    "type": "string",
                    "minLength": 1
                },
                "visibility": {
                    "enum": [
                        "PUBLIC",
                        "NDA"
                    ]
                },
                "sealed_private_pack_sha256": {
                    "type": "string"
                }
            },
            "additionalProperties": true
        },
        "AiepGenericRecord": {
            "title": "AIEP Generic Record (open extension)",
            "description": "Catch-all for structural index files, protocol-level files (citation, version, discovery, registry), and future or custom AIEP record types. Any valid JSON object passes.",
            "type": "object",
            "additionalProperties": true
        }
    }
}