{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://getzero.dev/contracts/zero.coliseum.league_retention.v0.schema.json",
  "title": "ZERO Coliseum League retention v0",
  "description": "Public read-only retention gate for weekly paper Coliseum bracket samples and League promotion evidence. This contract never executes orders and never publishes performance claims.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "kind",
    "public",
    "generated_at",
    "current_week",
    "execution_boundary",
    "retention_policy",
    "score_gate",
    "league_summary",
    "samples"
  ],
  "properties": {
    "schema_version": { "const": "zero.coliseum.league_retention.v0" },
    "kind": { "const": "coliseum_league_retention" },
    "public": { "const": true },
    "generated_at": { "type": "string", "format": "date-time" },
    "current_week": { "$ref": "#/$defs/week" },
    "execution_boundary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "can_execute_orders",
        "auto_execution_enabled",
        "private_keys_required",
        "live_promotion_requires_operator_lease",
        "default_disciple_mode",
        "can_publish_performance_claims"
      ],
      "properties": {
        "can_execute_orders": { "const": false },
        "auto_execution_enabled": { "const": false },
        "private_keys_required": { "const": false },
        "live_promotion_requires_operator_lease": { "const": true },
        "default_disciple_mode": { "const": "signal_only" },
        "can_publish_performance_claims": { "const": false }
      }
    },
    "retention_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "artifact_name",
        "report_path",
        "history_path",
        "retention_days",
        "minimum_distinct_weeks_for_public_promotion"
      ],
      "properties": {
        "artifact_name": { "const": "coliseum-league-retention" },
        "report_path": { "const": "artifacts/coliseum-league-retention/report.json" },
        "history_path": { "const": "artifacts/coliseum-league-retention/history.json" },
        "retention_days": { "const": 90 },
        "minimum_distinct_weeks_for_public_promotion": { "const": 3 }
      }
    },
    "score_gate": {
      "type": "object",
      "additionalProperties": false,
      "required": ["state", "can_promote_public_score", "reason", "next_action"],
      "properties": {
        "state": { "enum": ["collecting_history", "retention_ready"] },
        "can_promote_public_score": { "type": "boolean" },
        "reason": { "type": "string", "minLength": 20 },
        "next_action": { "enum": ["keep_weekly_retention_running", "collect_more_weekly_brackets"] }
      }
    },
    "league_summary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["tiers", "promotion_candidates", "relegation_candidates", "disqualified"],
      "properties": {
        "tiers": {
          "type": "array",
          "minItems": 5,
          "maxItems": 5,
          "items": { "$ref": "#/$defs/tier_summary" }
        },
        "promotion_candidates": {
          "type": "array",
          "items": { "$ref": "#/$defs/league_movement" }
        },
        "relegation_candidates": {
          "type": "array",
          "items": { "$ref": "#/$defs/league_movement" }
        },
        "disqualified": {
          "type": "array",
          "items": { "$ref": "#/$defs/league_movement" }
        }
      }
    },
    "samples": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/retained_sample" }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "score_gate": {
            "properties": {
              "state": { "const": "retention_ready" }
            },
            "required": ["state"]
          }
        },
        "required": ["score_gate"]
      },
      "then": {
        "properties": {
          "score_gate": {
            "properties": {
              "can_promote_public_score": { "const": true },
              "next_action": { "const": "keep_weekly_retention_running" }
            },
            "required": ["can_promote_public_score", "next_action"]
          },
          "samples": { "minItems": 3 }
        },
        "required": ["score_gate", "samples"]
      },
      "else": {
        "properties": {
          "score_gate": {
            "properties": {
              "state": { "const": "collecting_history" },
              "can_promote_public_score": { "const": false },
              "next_action": { "const": "collect_more_weekly_brackets" }
            },
            "required": ["state", "can_promote_public_score", "next_action"]
          }
        },
        "required": ["score_gate"]
      }
    }
  ],
  "$defs": {
    "tier": {
      "enum": ["Bronze", "Silver", "Gold", "Diamond", "Mythic"]
    },
    "week": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "week_start", "week_end", "bracket_url", "league_url"],
      "properties": {
        "id": { "type": "string", "minLength": 8 },
        "name": { "const": "Genesis Paper Bracket" },
        "week_start": { "type": "string", "format": "date" },
        "week_end": { "type": "string", "format": "date" },
        "bracket_url": { "const": "https://getzero.dev/coliseum" },
        "league_url": { "const": "https://getzero.dev/league" }
      }
    },
    "tier_counts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["Bronze", "Silver", "Gold", "Diamond", "Mythic"],
      "properties": {
        "Bronze": { "type": "integer", "minimum": 0 },
        "Silver": { "type": "integer", "minimum": 0 },
        "Gold": { "type": "integer", "minimum": 0 },
        "Diamond": { "type": "integer", "minimum": 0 },
        "Mythic": { "type": "integer", "minimum": 0 }
      }
    },
    "tier_summary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["tier", "entrants", "leader_entrant_id", "leader_profile_url"],
      "properties": {
        "tier": { "$ref": "#/$defs/tier" },
        "entrants": { "type": "integer", "minimum": 0 },
        "leader_entrant_id": { "type": ["string", "null"], "minLength": 3 },
        "leader_profile_url": { "type": ["string", "null"], "pattern": "^/(u|a)/" }
      }
    },
    "league_movement": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "entrant_id",
        "display_name",
        "from_tier",
        "to_tier",
        "reason",
        "replay_evidence_url",
        "public_profile_url"
      ],
      "properties": {
        "entrant_id": { "type": "string", "minLength": 3 },
        "display_name": { "type": "string", "minLength": 3 },
        "from_tier": {
          "anyOf": [
            { "$ref": "#/$defs/tier" },
            { "type": "null" }
          ]
        },
        "to_tier": { "$ref": "#/$defs/tier" },
        "reason": { "type": "string", "minLength": 8 },
        "replay_evidence_url": { "type": "string", "pattern": "^/(api/replays|replay)" },
        "public_profile_url": { "type": "string", "pattern": "^/(u|a)/" }
      }
    },
    "retained_sample": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source",
        "provenance",
        "generated_at",
        "tournament_id",
        "week_start",
        "week_end",
        "winner_entrant_id",
        "winner_tier",
        "entrants",
        "disqualified",
        "tier_counts",
        "promotion_candidates",
        "relegation_candidates",
        "execution_mode",
        "public_numeric_score_enabled"
      ],
      "properties": {
        "source": { "enum": ["current_public_contract", "retained_workflow_report"] },
        "source_path": { "type": "string", "minLength": 3 },
        "provenance": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "artifact_kind",
            "eligibility",
            "contract_url",
            "public_readback_url",
            "execution_boundary",
            "performance_claims",
            "backfill_approved"
          ],
          "properties": {
            "artifact_kind": {
              "enum": ["current_public_contract", "workflow_report", "imported_backfill_report"]
            },
            "eligibility": { "const": "retained_weekly_paper_bracket" },
            "contract_url": {
              "const": "https://getzero.dev/contracts/zero.coliseum.league_retention.v0.schema.json"
            },
            "public_readback_url": { "const": "https://getzero.dev/api/coliseum/history" },
            "execution_boundary": { "const": "paper_only_no_orders" },
            "performance_claims": { "const": "disabled" },
            "backfill_approved": { "type": "boolean" }
          }
        },
        "generated_at": {
          "anyOf": [
            { "type": "string", "format": "date-time" },
            { "type": "null" }
          ]
        },
        "tournament_id": { "type": "string", "minLength": 8 },
        "week_start": { "type": "string", "format": "date" },
        "week_end": { "type": "string", "format": "date" },
        "winner_entrant_id": { "type": "string", "minLength": 3 },
        "winner_tier": { "$ref": "#/$defs/tier" },
        "entrants": { "type": "integer", "minimum": 0 },
        "disqualified": { "type": "integer", "minimum": 0 },
        "tier_counts": { "$ref": "#/$defs/tier_counts" },
        "promotion_candidates": {
          "type": "array",
          "items": { "type": "string", "minLength": 3 }
        },
        "relegation_candidates": {
          "type": "array",
          "items": { "type": "string", "minLength": 3 }
        },
        "execution_mode": { "const": "paper" },
        "public_numeric_score_enabled": { "const": false }
      }
    }
  }
}
