{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://alphatest.dev/schemas/governed-source-release-v6.json",
  "title": "AlphaTest governed source, public inventory binding, and calibration release catalog",
  "type": "object",
  "required": ["schema_version", "release_state", "catalog_revision_hash", "catalog_revision_hash_scope", "calibration_lifecycle_contract", "source_assessments", "release_behavior"],
  "properties": {
    "schema_version": {"const": 6},
    "release_state": {"enum": ["blocked_pending_reviewer_credential_preflight", "ready"]},
    "catalog_revision_hash": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
    "catalog_revision_hash_scope": {"type": "string", "minLength": 1},
    "calibration_lifecycle_contract": {
      "type": "object",
      "required": ["identity_fields", "initial_creation_evidence", "empirical_revision_owners", "cardinality", "promotion_rule"],
      "properties": {
        "empirical_revision_owners": {"const": ["results", "analytics"]}
      }
    },
    "source_assessments": {
      "type": "array",
      "minItems": 2,
      "maxItems": 50,
      "items": {"$ref": "#/$defs/source"}
    },
    "release_behavior": {
      "type": "object",
      "required": ["create_http_status", "operation_created", "quickstart_state", "ready_gate", "failure_atomicity", "empirical_revision_trigger"],
      "properties": {
        "create_http_status": {"enum": [202, 503]},
        "operation_created": {"type": "boolean"}
      }
    }
  },
  "$defs": {
    "source": {
      "type": "object",
      "required": ["tenant_id", "source_key", "content_test_spec_id", "content_version_id", "release_state", "tested_standard_inventory", "public_inventory_cell_binding_manifest", "calibration"],
      "properties": {
        "release_state": {"enum": ["blocked_missing_public_inventory_bindings", "ready"]},
        "tested_standard_inventory": {
          "type": "array",
          "minItems": 1,
          "items": {"$ref": "#/$defs/testedStandard"}
        },
        "public_inventory_cell_binding_manifest": {"$ref": "#/$defs/bindingManifest"},
        "calibration": {"$ref": "#/$defs/calibration"}
      }
    },
    "testedStandard": {
      "type": "object",
      "required": ["source_standard_code", "label", "dok", "evidence_locator", "runtime_mapping_disposition"],
      "properties": {
        "source_standard_code": {"type": "string", "minLength": 1},
        "label": {"type": "string", "minLength": 1},
        "dok": {"oneOf": [{"enum": [1, 2, 3, 4]}, {"const": "unstated"}]},
        "evidence_locator": {"type": "string", "minLength": 1},
        "runtime_mapping_disposition": {"type": "string", "minLength": 1}
      }
    },
    "bindingManifest": {
      "type": "object",
      "required": ["state", "authority", "authority_version", "expected_public_row_count", "expected_positive_content_cell_count", "bindings"],
      "properties": {
        "state": {"enum": ["blocked_missing_owner_approved_bindings", "ready"]},
        "authority": {"type": ["string", "null"]},
        "authority_version": {"type": ["string", "null"]},
        "expected_public_row_count": {"type": "integer", "minimum": 1},
        "expected_positive_content_cell_count": {"type": "integer", "minimum": 1},
        "bindings": {
          "type": "array",
          "items": {"$ref": "#/$defs/publicInventoryCellBinding"}
        }
      },
      "additionalProperties": false
    },
    "publicInventoryCellBinding": {
      "type": "object",
      "required": ["source_key", "public_row_code", "content_test_spec_id", "content_version_id", "source_case_guid", "source_dok", "source_cell_count", "binding_authority", "binding_authority_version", "approved_by", "approved_at", "evidence_ref"],
      "properties": {
        "source_key": {"type": "string", "minLength": 1},
        "public_row_code": {"type": "string", "minLength": 1},
        "content_test_spec_id": {"type": "string", "minLength": 1},
        "content_version_id": {"type": "string", "minLength": 1},
        "source_case_guid": {"type": "string", "minLength": 1},
        "source_dok": {"enum": [1, 2, 3, 4]},
        "source_cell_count": {"type": "integer", "minimum": 1},
        "binding_authority": {"type": "string", "minLength": 1},
        "binding_authority_version": {"type": "string", "minLength": 1},
        "approved_by": {"type": "string", "minLength": 1},
        "approved_at": {"type": "string", "format": "date-time"},
        "evidence_ref": {"type": "string", "minLength": 1}
      },
      "additionalProperties": false
    },
    "calibration": {
      "type": "object",
      "required": ["calibration_target_id", "metric", "target_value", "relation", "calibration_policy_version", "scoring_policy_ref", "approval", "empirical_revision_bindings"],
      "properties": {
        "metric": {"const": "equivalent_raw_score_percent"},
        "target_value": {"const": 100},
        "relation": {"const": "mastery_implies_at_least"},
        "empirical_revision_bindings": {
          "type": "object",
          "required": ["results", "analytics"],
          "properties": {
            "results": {"$ref": "#/$defs/binding"},
            "analytics": {"$ref": "#/$defs/binding"}
          },
          "additionalProperties": false
        }
      }
    },
    "binding": {
      "type": "object",
      "required": ["native_reference_id", "dereference_route", "credential_slot", "expected_identity", "receipt_ref", "state"],
      "properties": {
        "native_reference_id": {"type": ["string", "null"]},
        "receipt_ref": {"type": ["string", "null"]},
        "expected_identity": {
          "type": "object",
          "required": ["tenant_id", "source_key", "content_test_spec_id", "content_version_id", "calibration_target_id"],
          "properties": {
            "tenant_id": {"type": "string", "minLength": 1},
            "source_key": {"type": "string", "minLength": 1},
            "content_test_spec_id": {"type": "string", "minLength": 1},
            "content_version_id": {"type": "string", "minLength": 1},
            "calibration_target_id": {"type": "string", "minLength": 1}
          },
          "additionalProperties": false
        }
      }
    }
  }
}
