{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agla.invalid/schemas/machina-composable-profile.v1.schema.json",
  "title": "AGLA MACHINA Composable Profile Interface",
  "version": "1.0.0",
  "status": "CANDIDATE_NON_RUNTIME_NO_AUTHORITY_EFFECT",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "profile_id",
    "profile_version",
    "profile_kind",
    "native_schema_ref",
    "compatibility",
    "owner_ref",
    "validation_entrypoint",
    "lifecycle",
    "domain_contract",
    "presentation_bindings",
    "invariants"
  ],
  "properties": {
    "$schema": { "type": "string" },
    "profile_id": { "type": "string", "minLength": 1 },
    "profile_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
    "profile_kind": { "const": "MACHINA_COMPOSABLE_DOMAIN_PROFILE" },
    "native_schema_ref": { "$ref": "#/$defs/native_ref" },
    "compatibility": { "$ref": "#/$defs/compatibility" },
    "owner_ref": { "$ref": "#/$defs/owner_ref" },
    "validation_entrypoint": { "$ref": "#/$defs/entrypoint" },
    "lifecycle": { "$ref": "#/$defs/lifecycle" },
    "domain_contract": { "$ref": "#/$defs/domain_contract" },
    "presentation_bindings": { "$ref": "#/$defs/presentation_bindings" },
    "invariants": { "type": "object", "minProperties": 1, "additionalProperties": { "const": true } }
  },
  "$defs": {
    "native_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["schema_id", "schema_version", "artifact_path", "source_commit"],
      "properties": {
        "schema_id": { "type": "string" },
        "schema_version": { "type": "string" },
        "artifact_path": { "type": "string" },
        "source_commit": { "type": "string", "pattern": "^[a-f0-9]{40}$" }
      }
    },
    "compatibility": {
      "type": "object",
      "additionalProperties": false,
      "required": ["envelope_interface", "native_schema_range", "bridge_interface", "common_core_status"],
      "properties": {
        "envelope_interface": { "const": "MACHINA_THIN_ENVELOPE_V1" },
        "native_schema_range": { "type": "string" },
        "bridge_interface": { "const": "MACHINA_EXTERNAL_BRIDGE_V1" },
        "common_core_status": { "const": "DEFERRED_PENDING_MULTIPLE_REAL_PROFILES" }
      }
    },
    "owner_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["owner_id", "owner_class", "authority_transfer"],
      "properties": {
        "owner_id": { "type": "string" },
        "owner_class": { "enum": ["TENET", "ROTAS", "AREPO", "OPERA", "SATOR"] },
        "authority_transfer": { "const": false }
      }
    },
    "entrypoint": {
      "type": "object",
      "additionalProperties": false,
      "required": ["validator_path", "mode", "execution_effect"],
      "properties": {
        "validator_path": { "type": "string" },
        "mode": { "const": "STATIC_REPRESENTATION_VALIDATION" },
        "execution_effect": { "const": "NONE" }
      }
    },
    "lifecycle": {
      "type": "object",
      "additionalProperties": false,
      "required": ["state", "canonicality", "runtime", "promotion_authority"],
      "properties": {
        "state": { "const": "CANDIDATE" },
        "canonicality": { "const": "NON_CANONICAL" },
        "runtime": { "const": "NON_RUNTIME" },
        "promotion_authority": { "const": "NONE" }
      }
    },
    "count_contract": {
      "type": "object",
      "additionalProperties": false,
      "required": ["wheels", "loci", "cycle_order_views", "axes", "directed_carriers", "pair_keys"],
      "properties": {
        "wheels": { "type": "integer", "minimum": 0 },
        "loci": { "type": "integer", "minimum": 0 },
        "cycle_order_views": { "type": "integer", "minimum": 0 },
        "axes": { "type": "integer", "minimum": 0 },
        "directed_carriers": { "type": "integer", "minimum": 0 },
        "pair_keys": { "type": "integer", "minimum": 0 }
      }
    },
    "domain_contract": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "domain_id",
        "selectors",
        "structure_counts",
        "source_id_sets",
        "state_identity",
        "lexical_surface_contract",
        "optional_camera_refs"
      ],
      "properties": {
        "domain_id": { "const": "ROTA_A_DUPLEX" },
        "selectors": { "type": "array", "minItems": 9, "maxItems": 9, "uniqueItems": true, "items": { "type": "string" } },
        "structure_counts": { "$ref": "#/$defs/count_contract" },
        "source_id_sets": {
          "type": "object",
          "additionalProperties": false,
          "required": ["wheels", "loci", "cycles", "axes", "carriers", "pair_keys"],
          "properties": {
            "wheels": { "$ref": "#/$defs/id_array" },
            "loci": { "$ref": "#/$defs/id_array" },
            "cycles": { "$ref": "#/$defs/id_array" },
            "axes": { "$ref": "#/$defs/id_array" },
            "carriers": { "$ref": "#/$defs/id_array" },
            "pair_keys": { "$ref": "#/$defs/id_array" }
          }
        },
        "state_identity": {
          "type": "object",
          "additionalProperties": false,
          "required": ["ordered_fields", "pair_keys_stateless", "primary_store"],
          "properties": {
            "ordered_fields": {
              "type": "array",
              "prefixItems": [
                { "const": "carrier_id" },
                { "const": "context_id" },
                { "const": "execution_id" }
              ],
              "items": false
            },
            "pair_keys_stateless": { "const": true },
            "primary_store": { "const": "CARRIER_RESULTS" }
          }
        },
        "lexical_surface_contract": {
          "type": "object",
          "additionalProperties": false,
          "required": ["citation_form_distinct", "contextual_surface_distinct", "form_ids"],
          "properties": {
            "citation_form_distinct": { "const": true },
            "contextual_surface_distinct": { "const": true },
            "form_ids": { "$ref": "#/$defs/id_array" }
          }
        },
        "optional_camera_refs": {
          "type": "object",
          "additionalProperties": false,
          "required": ["provider", "status", "refs", "pair_keys_are_cameras"],
          "properties": {
            "provider": { "const": "STACK_G_EXTERNAL" },
            "status": { "enum": ["NOT_SUPPLIED", "REFERENCED_EXTERNALLY"] },
            "refs": { "type": "array", "items": { "type": "string" } },
            "pair_keys_are_cameras": { "const": false }
          }
        }
      }
    },
    "id_array": {
      "type": "array",
      "uniqueItems": true,
      "items": { "type": "string", "minLength": 1 }
    },
    "binding": {
      "type": "object",
      "additionalProperties": false,
      "required": ["binding_kind", "authority", "source_ref"],
      "properties": {
        "binding_kind": { "enum": ["SEMANTIC_POSE", "VIEW_ALIGNMENT", "GLYPH_PRESENTATION", "UI_PROJECTION"] },
        "authority": { "const": "PRESENTATION_ONLY_NO_EXECUTION_EFFECT" },
        "source_ref": { "type": "string" }
      }
    },
    "presentation_bindings": {
      "type": "array",
      "minItems": 4,
      "uniqueItems": true,
      "items": { "$ref": "#/$defs/binding" }
    }
  }
}
