{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:awoooi:source-control-primary-readiness-gate-v1",
  "title": "Gitea 到 GitHub Primary Readiness Gate v1",
  "description": "定義 GitHub primary cutover 前，AwoooP 需要只讀顯示的 parity、owner、rollback 與人工批准門檻。此契約只做 gate 準備，不授權 repo、refs 或 primary switch。",
  "type": "object",
  "required": [
    "schema_version",
    "status",
    "date",
    "mode",
    "runtime_execution_authorized",
    "source_indexes",
    "summary",
    "global_readiness_gates",
    "repo_readiness",
    "gate_rules",
    "forbidden_actions"
  ],
  "properties": {
    "schema_version": {
      "const": "source_control_primary_readiness_gate_v1"
    },
    "status": {
      "type": "string",
      "enum": ["draft_blocked"]
    },
    "date": {
      "type": "string"
    },
    "mode": {
      "type": "string",
      "enum": ["primary_readiness_gate_only"]
    },
    "runtime_execution_authorized": {
      "type": "boolean",
      "const": false
    },
    "source_indexes": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "minItems": 1
    },
    "summary": {
      "type": "object",
      "required": [
        "candidate_repo_count",
        "in_scope_repo_count",
        "external_scope_count",
        "primary_ready_count",
        "blocked_in_scope_count",
        "approval_required_count",
        "runtime_actions_authorized",
        "github_primary_switch_authorized",
        "action_buttons_allowed",
        "raw_secret_storage_authorized"
      ],
      "properties": {
        "candidate_repo_count": {
          "type": "integer",
          "minimum": 0
        },
        "in_scope_repo_count": {
          "type": "integer",
          "minimum": 0
        },
        "external_scope_count": {
          "type": "integer",
          "minimum": 0
        },
        "primary_ready_count": {
          "type": "integer",
          "minimum": 0
        },
        "blocked_in_scope_count": {
          "type": "integer",
          "minimum": 0
        },
        "approval_required_count": {
          "type": "integer",
          "minimum": 0
        },
        "runtime_actions_authorized": {
          "type": "boolean",
          "const": false
        },
        "github_primary_switch_authorized": {
          "type": "boolean",
          "const": false
        },
        "action_buttons_allowed": {
          "type": "boolean",
          "const": false
        },
        "raw_secret_storage_authorized": {
          "type": "boolean",
          "const": false
        }
      },
      "additionalProperties": false
    },
    "global_readiness_gates": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "gate_id",
          "title",
          "status",
          "required_before_primary",
          "current_gap",
          "allowed_now",
          "execution_authorized"
        ],
        "properties": {
          "gate_id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": ["blocked", "pending_review", "missing_evidence", "not_started"]
          },
          "required_before_primary": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1
          },
          "current_gap": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1
          },
          "allowed_now": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1
          },
          "execution_authorized": {
            "type": "boolean",
            "const": false
          }
        },
        "additionalProperties": false
      }
    },
    "repo_readiness": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "github_repo",
          "source_key",
          "scope_status",
          "readiness_state",
          "risk",
          "target_state",
          "primary_ready",
          "blockers",
          "evidence_refs",
          "allowed_now",
          "still_forbidden"
        ],
        "properties": {
          "github_repo": {
            "type": "string"
          },
          "source_key": {
            "type": "string"
          },
          "scope_status": {
            "type": "string",
            "enum": ["in_scope", "external_scope_review"]
          },
          "readiness_state": {
            "type": "string",
            "enum": [
              "blocked_waiting_refs_parity",
              "blocked_waiting_internal_remote_decision",
              "blocked_waiting_target_decision",
              "observe_scope_review"
            ]
          },
          "risk": {
            "type": "string",
            "enum": ["LOW", "MEDIUM", "HIGH"]
          },
          "target_state": {
            "type": "string"
          },
          "primary_ready": {
            "type": "boolean",
            "const": false
          },
          "blockers": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1
          },
          "evidence_refs": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1
          },
          "allowed_now": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1
          },
          "still_forbidden": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1
          }
        },
        "additionalProperties": false
      }
    },
    "gate_rules": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "minItems": 1
    },
    "forbidden_actions": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "minItems": 1
    }
  },
  "additionalProperties": false
}
