{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:awoooi:gitea-authenticated-inventory-import-acceptance-v1",
  "title": "Gitea 認證清冊匯入驗收契約 v1",
  "description": "定義 Gitea 私有 / 內部 repo 清冊的脫敏 payload 驗收、拒收、隔離與允許輸出。此 schema 不授權匯入 token value、Gitea DB dump、git object、repo 寫入、refs sync 或 GitHub primary cutover。",
  "type": "object",
  "required": [
    "schema_version",
    "status",
    "date",
    "mode",
    "runtime_execution_authorized",
    "source_contract",
    "source_request_contract",
    "source_indexes",
    "summary",
    "payload_shape",
    "acceptance_checks",
    "rejection_rules",
    "quarantine_mapping",
    "allowed_outputs",
    "forbidden_actions"
  ],
  "properties": {
    "schema_version": {
      "const": "gitea_authenticated_inventory_import_acceptance_v1"
    },
    "status": {
      "type": "string",
      "enum": ["draft_waiting_redacted_inventory_payload"]
    },
    "date": {
      "type": "string"
    },
    "mode": {
      "type": "string",
      "enum": ["redacted_payload_acceptance_only"]
    },
    "runtime_execution_authorized": {
      "type": "boolean",
      "const": false
    },
    "source_contract": {
      "type": "string",
      "const": "gitea_repo_inventory_v1"
    },
    "source_request_contract": {
      "type": "string",
      "const": "gitea_authenticated_inventory_export_request_v1"
    },
    "source_indexes": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    },
    "summary": {
      "type": "object",
      "required": [
        "target_contract",
        "import_payload_status",
        "accepted_visibility_scopes",
        "minimum_repo_count",
        "local_gitea_unique_repo_count",
        "required_gap_explanation_count",
        "received_payload_count",
        "accepted_payload_count",
        "rejected_payload_count",
        "acceptance_check_count",
        "rejection_rule_count",
        "quarantine_required_for_sensitive_payload",
        "token_value_collection_allowed",
        "raw_secret_allowed",
        "db_dump_allowed",
        "git_object_import_allowed",
        "repo_write_allowed",
        "refs_sync_allowed",
        "github_primary_switch_authorized",
        "action_buttons_allowed"
      ],
      "properties": {
        "target_contract": {
          "type": "string",
          "const": "gitea_repo_inventory_v1.status=ok"
        },
        "import_payload_status": {
          "type": "string",
          "enum": ["waiting_redacted_payload"]
        },
        "accepted_visibility_scopes": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["authenticated", "admin_export"]
          },
          "minItems": 1
        },
        "minimum_repo_count": {"type": "integer", "minimum": 0},
        "local_gitea_unique_repo_count": {"type": "integer", "minimum": 0},
        "required_gap_explanation_count": {"type": "integer", "minimum": 0},
        "received_payload_count": {"type": "integer", "minimum": 0},
        "accepted_payload_count": {"type": "integer", "minimum": 0},
        "rejected_payload_count": {"type": "integer", "minimum": 0},
        "acceptance_check_count": {"type": "integer", "minimum": 0},
        "rejection_rule_count": {"type": "integer", "minimum": 0},
        "quarantine_required_for_sensitive_payload": {
          "type": "boolean",
          "const": true
        },
        "token_value_collection_allowed": {"type": "boolean", "const": false},
        "raw_secret_allowed": {"type": "boolean", "const": false},
        "db_dump_allowed": {"type": "boolean", "const": false},
        "git_object_import_allowed": {"type": "boolean", "const": false},
        "repo_write_allowed": {"type": "boolean", "const": false},
        "refs_sync_allowed": {"type": "boolean", "const": false},
        "github_primary_switch_authorized": {"type": "boolean", "const": false},
        "action_buttons_allowed": {"type": "boolean", "const": false}
      },
      "additionalProperties": false
    },
    "payload_shape": {
      "type": "object",
      "required": [
        "required_top_level_fields",
        "required_repo_fields",
        "required_attestations",
        "field_constraints"
      ],
      "properties": {
        "required_top_level_fields": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        },
        "required_repo_fields": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        },
        "required_attestations": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        },
        "field_constraints": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        }
      },
      "additionalProperties": false
    },
    "acceptance_checks": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "check_id",
          "title",
          "required",
          "pass_condition",
          "failure_lane",
          "execution_authorized"
        ],
        "properties": {
          "check_id": {"type": "string"},
          "title": {"type": "string"},
          "required": {"type": "boolean"},
          "pass_condition": {"type": "string"},
          "failure_lane": {"type": "string"},
          "execution_authorized": {"type": "boolean", "const": false}
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "rejection_rules": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    },
    "quarantine_mapping": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["condition", "target_lane", "execution_authorized"],
        "properties": {
          "condition": {"type": "string"},
          "target_lane": {"type": "string"},
          "execution_authorized": {"type": "boolean", "const": false}
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "allowed_outputs": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    },
    "forbidden_actions": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    }
  },
  "additionalProperties": false
}
