{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://getzero.dev/contracts/zero.intelligence_warehouse.v1.schema.json",
  "title": "ZERO Intelligence Warehouse Contract v1",
  "description": "Machine-readable source, join, privacy, and governance contract for ZERO intelligence warehouse materialization.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "schema",
    "kind",
    "public_contract",
    "status",
    "generated_at",
    "source_refs",
    "execution_boundary",
    "privacy_boundary",
    "source_tables",
    "canonical_events",
    "taxonomies",
    "joins",
    "read_models",
    "promotion_policy",
    "blockers"
  ],
  "properties": {
    "schema_version": { "const": "zero.intelligence_warehouse.v1" },
    "schema": { "const": "https://getzero.dev/contracts/zero.intelligence_warehouse.v1.schema.json" },
    "kind": { "const": "intelligence_warehouse_contract" },
    "public_contract": { "const": true },
    "status": {
      "enum": [
        "contract_ready_materialization_missing",
        "contract_ready_materialization_repo_ready",
        "warehouse_ready",
        "degraded"
      ]
    },
    "generated_at": { "type": "string", "format": "date-time" },
    "source_refs": {
      "type": "array",
      "minItems": 6,
      "uniqueItems": true,
      "items": { "type": "string", "minLength": 8 }
    },
    "execution_boundary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "warehouse_can_execute_orders",
        "auto_execution_enabled",
        "can_execute_exchange_orders",
        "can_custody_assets",
        "can_move_funds",
        "can_train_without_operator_review",
        "can_promote_memory_without_operator_action",
        "can_export_identifiers",
        "can_publish_operator_private_rows"
      ],
      "properties": {
        "warehouse_can_execute_orders": { "const": false },
        "auto_execution_enabled": { "const": false },
        "can_execute_exchange_orders": { "const": false },
        "can_custody_assets": { "const": false },
        "can_move_funds": { "const": false },
        "can_train_without_operator_review": { "const": false },
        "can_promote_memory_without_operator_action": { "const": false },
        "can_export_identifiers": { "const": false },
        "can_publish_operator_private_rows": { "const": false }
      }
    },
    "privacy_boundary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "operator_scoped_private_rows",
        "public_outputs_aggregate_only",
        "curated_public_proof_required_for_public_replay_rows",
        "raw_operator_ids_public",
        "analytics_identity_like_keys_ingested",
        "contact_fields_ingested",
        "wallet_fields_ingested",
        "secret_material_ingested",
        "nested_analytics_properties_ingested",
        "default_retention"
      ],
      "properties": {
        "operator_scoped_private_rows": { "const": true },
        "public_outputs_aggregate_only": { "const": true },
        "curated_public_proof_required_for_public_replay_rows": { "const": true },
        "raw_operator_ids_public": { "const": false },
        "analytics_identity_like_keys_ingested": { "const": false },
        "contact_fields_ingested": { "const": false },
        "wallet_fields_ingested": { "const": false },
        "secret_material_ingested": { "const": false },
        "nested_analytics_properties_ingested": { "const": false },
        "default_retention": { "const": "bounded_by_source_contracts_and_erasure_controls" }
      }
    },
    "source_tables": {
      "type": "array",
      "minItems": 8,
      "items": { "$ref": "#/$defs/source_table" }
    },
    "canonical_events": {
      "type": "array",
      "minItems": 10,
      "items": { "$ref": "#/$defs/canonical_event" }
    },
    "taxonomies": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "analytics_events",
        "journey_stages",
        "proposal_actions",
        "proposal_statuses",
        "memory_actions",
        "memory_categories",
        "growth_intents"
      ],
      "properties": {
        "analytics_events": {
          "type": "array",
          "minItems": 8,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 3 }
        },
        "journey_stages": {
          "type": "array",
          "minItems": 10,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 3 }
        },
        "proposal_actions": {
          "type": "array",
          "minItems": 4,
          "uniqueItems": true,
          "items": { "enum": ["create", "approve", "edit", "reject"] }
        },
        "proposal_statuses": {
          "type": "array",
          "minItems": 5,
          "uniqueItems": true,
          "items": { "enum": ["proposed", "approved", "edited", "rejected", "committed"] }
        },
        "memory_actions": {
          "type": "array",
          "minItems": 5,
          "uniqueItems": true,
          "items": { "enum": ["promote", "reject", "correct", "delete", "rollback"] }
        },
        "memory_categories": {
          "type": "array",
          "minItems": 6,
          "uniqueItems": true,
          "items": { "enum": ["refusal", "override", "outcome", "proposal", "growth_signal", "data_quality"] }
        },
        "growth_intents": {
          "type": "array",
          "minItems": 7,
          "uniqueItems": true,
          "items": {
            "enum": [
              "follow",
              "disciple_signal_only",
              "save_trade_receipt",
              "clone_agent",
              "spawn_paper_run",
              "referral",
              "marketplace_demand"
            ]
          }
        }
      }
    },
    "joins": {
      "type": "array",
      "minItems": 4,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "from", "to", "then_to", "purpose", "status"],
        "properties": {
          "id": { "type": "string", "minLength": 8 },
          "from": { "type": "string", "minLength": 4 },
          "to": { "type": "string", "minLength": 4 },
          "then_to": { "type": "string", "minLength": 4 },
          "purpose": { "type": "string", "minLength": 20 },
          "status": {
            "enum": [
              "available_after_proposal_and_memory_migrations",
              "contract_defined_materialization_missing",
              "available_after_growth_migration",
              "repo_ready_real_fill_import_required",
              "warehouse_ready"
            ]
          }
        }
      }
    },
    "read_models": {
      "type": "array",
      "minItems": 4,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "visibility",
          "grain",
          "sources",
          "required_controls",
          "current_status"
        ],
        "properties": {
          "id": { "type": "string", "minLength": 8 },
          "visibility": { "enum": ["operator_private", "public_aggregate", "aggregate_only"] },
          "grain": { "type": "string", "minLength": 4 },
          "sources": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true,
            "items": { "$ref": "#/$defs/source_name" }
          },
          "required_controls": {
            "type": "array",
            "minItems": 1,
            "items": { "type": "string", "minLength": 3 }
          },
          "current_status": {
            "enum": [
              "partially_available_via_api_operator_memory",
              "materialization_repo_ready_migration_required",
              "repo_ready_growth_migration_required",
              "contract_defined_materialization_missing",
              "materialization_repo_ready_real_fill_import_required",
              "repo_ready_real_fill_import_required",
              "warehouse_ready"
            ]
          }
        }
      }
    },
    "promotion_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "auto_promotion_enabled",
        "operator_action_required",
        "allowed_actions",
        "correction_required_for_edits",
        "rollback_supported",
        "public_aggregate_promotion_requires_scope",
        "model_training_allowed_without_review"
      ],
      "properties": {
        "auto_promotion_enabled": { "const": false },
        "operator_action_required": { "const": true },
        "allowed_actions": {
          "type": "array",
          "minItems": 5,
          "uniqueItems": true,
          "items": { "enum": ["promote", "reject", "correct", "delete", "rollback"] }
        },
        "correction_required_for_edits": { "const": true },
        "rollback_supported": { "const": true },
        "public_aggregate_promotion_requires_scope": { "const": true },
        "model_training_allowed_without_review": { "const": false }
      }
    },
    "blockers": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "severity", "description"],
        "properties": {
          "id": { "type": "string", "minLength": 8 },
          "severity": { "enum": ["data_asset", "deployment", "governance", "revenue_truth"] },
          "description": { "type": "string", "minLength": 20 }
        }
      }
    }
  },
  "$defs": {
    "source_name": {
      "enum": [
        "analytics_event",
        "decision_replay",
        "deployment_event",
        "growth_intent",
        "agent_proposal",
        "operator_memory",
        "journey_progress",
        "runtime_capability"
      ]
    },
    "source_table": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source",
        "table",
        "visibility",
        "primary_time",
        "join_keys",
        "captures",
        "privacy_policy"
      ],
      "properties": {
        "source": { "$ref": "#/$defs/source_name" },
        "table": { "type": "string", "minLength": 3 },
        "visibility": { "enum": ["operator_private", "public_aggregate", "public_contract"] },
        "primary_time": { "type": "string", "minLength": 3 },
        "join_keys": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "minLength": 2 }
        },
        "captures": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "minLength": 3 }
        },
        "privacy_policy": { "type": "string", "minLength": 20 }
      }
    },
    "canonical_event": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "category",
        "source",
        "source_event",
        "public_output",
        "can_promote_to_memory",
        "operator_review_required"
      ],
      "properties": {
        "id": { "type": "string", "minLength": 6 },
        "category": {
          "enum": [
            "conversion",
            "refusal",
            "paper_outcome",
            "proposal_review",
            "memory_action",
            "growth_signal",
            "journey_stage",
            "revenue_reconciliation",
            "data_quality"
          ]
        },
        "source": { "$ref": "#/$defs/source_name" },
        "source_event": { "type": "string", "minLength": 3 },
        "public_output": { "enum": ["none", "aggregate_only", "curated_public_proof"] },
        "can_promote_to_memory": { "type": "boolean" },
        "operator_review_required": { "type": "boolean" }
      }
    }
  }
}
