{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:awoooi:gitea-authenticated-inventory-export-request-v1",
  "title": "Gitea Authenticated Inventory Export Request v1",
  "description": "定義 Gitea private/internal 全量 repo inventory 的只讀 token 或管理匯出請求、允許欄位、拒收欄位與驗收 gate。此 schema 不授權讀取 token value、repo 寫入、refs sync 或 GitHub primary cutover。",
  "type": "object",
  "required": [
    "schema_version",
    "status",
    "date",
    "mode",
    "runtime_execution_authorized",
    "source_contract",
    "source_indexes",
    "summary",
    "export_source_options",
    "required_inventory_fields",
    "coverage_gap_hints",
    "request_dispatch_preflight_checks",
    "request_handoff_packet",
    "post_dispatch_invariants",
    "acceptance_rules",
    "redaction_rules",
    "forbidden_actions"
  ],
  "properties": {
    "schema_version": {
      "const": "gitea_authenticated_inventory_export_request_v1"
    },
    "status": {
      "type": "string",
      "enum": ["draft_waiting_owner_export"]
    },
    "date": {
      "type": "string"
    },
    "mode": {
      "type": "string",
      "enum": ["redacted_export_request_only"]
    },
    "runtime_execution_authorized": {
      "type": "boolean",
      "const": false
    },
    "source_contract": {
      "type": "string",
      "const": "gitea_repo_inventory_v1"
    },
    "source_indexes": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    },
    "summary": {
      "type": "object",
      "required": [
        "gitea_base_url",
        "org_or_user",
        "public_only_repo_count",
        "local_gitea_unique_repo_count",
        "local_gitea_gap_count",
        "export_source_option_count",
        "target_inventory_status",
        "token_value_collection_allowed",
        "write_token_allowed",
        "repo_write_allowed",
        "refs_sync_allowed",
        "github_primary_switch_authorized",
        "action_buttons_allowed",
        "s4_9_owner_response_gate_required",
        "request_handoff_package_ready",
        "request_dispatch_handoff_completion_percent",
        "request_packet_field_count",
        "request_dispatch_authorized",
        "admin_export_payload_received_count",
        "admin_export_payload_accepted_count",
        "inventory_imported_count",
        "runtime_inventory_execution_authorized"
      ],
      "properties": {
        "gitea_base_url": {"type": "string"},
        "org_or_user": {"type": "string"},
        "public_only_repo_count": {"type": "integer", "minimum": 0},
        "local_gitea_unique_repo_count": {"type": "integer", "minimum": 0},
        "local_gitea_gap_count": {"type": "integer", "minimum": 0},
        "export_source_option_count": {"type": "integer", "minimum": 0},
        "target_inventory_status": {
          "type": "string",
          "enum": ["gitea_repo_inventory_v1.status=ok"]
        },
        "token_value_collection_allowed": {"type": "boolean", "const": false},
        "write_token_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},
        "s4_9_owner_response_gate_required": {"type": "boolean", "const": true},
        "request_handoff_package_ready": {"type": "boolean", "const": true},
        "request_dispatch_handoff_completion_percent": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100
        },
        "request_packet_field_count": {"type": "integer", "minimum": 0},
        "request_dispatch_authorized": {"type": "boolean", "const": false},
        "admin_export_payload_received_count": {"type": "integer", "minimum": 0},
        "admin_export_payload_accepted_count": {"type": "integer", "minimum": 0},
        "inventory_imported_count": {"type": "integer", "minimum": 0},
        "runtime_inventory_execution_authorized": {"type": "boolean", "const": false}
      },
      "additionalProperties": false
    },
    "export_source_options": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "option_id",
          "title",
          "request_status",
          "producer",
          "allowed_processing",
          "blocked_processing",
          "acceptance_gate",
          "execution_authorized"
        ],
        "properties": {
          "option_id": {"type": "string"},
          "title": {"type": "string"},
          "request_status": {
            "type": "string",
            "enum": ["waiting_human_approval_or_owner_export"]
          },
          "producer": {"type": "string"},
          "allowed_processing": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "blocked_processing": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "acceptance_gate": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "execution_authorized": {"type": "boolean", "const": false}
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "required_inventory_fields": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    },
    "coverage_gap_hints": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "gap_id",
          "title",
          "current_evidence",
          "required_resolution",
          "execution_authorized"
        ],
        "properties": {
          "gap_id": {"type": "string"},
          "title": {"type": "string"},
          "current_evidence": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "required_resolution": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "execution_authorized": {"type": "boolean", "const": false}
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "request_dispatch_preflight_checks": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "check_id",
          "display_order",
          "check",
          "current_status",
          "execution_authorized"
        ],
        "properties": {
          "check_id": {"type": "string"},
          "display_order": {"type": "integer", "minimum": 1},
          "check": {"type": "string"},
          "current_status": {
            "type": "string",
            "enum": ["defined_not_dispatched"]
          },
          "execution_authorized": {"type": "boolean", "const": false}
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "request_handoff_packet": {
      "type": "object",
      "required": [
        "request_id",
        "prerequisite_gate",
        "allowed_source_options",
        "recipient_role_or_team_required",
        "requested_outputs",
        "forbidden_inputs",
        "intake_acceptance_ref",
        "not_approval",
        "execution_authorized"
      ],
      "properties": {
        "request_id": {"type": "string"},
        "prerequisite_gate": {"type": "string"},
        "allowed_source_options": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        },
        "recipient_role_or_team_required": {"type": "boolean", "const": true},
        "requested_outputs": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        },
        "forbidden_inputs": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        },
        "intake_acceptance_ref": {"type": "string"},
        "not_approval": {"type": "boolean", "const": true},
        "execution_authorized": {"type": "boolean", "const": false}
      },
      "additionalProperties": false
    },
    "post_dispatch_invariants": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    },
    "acceptance_rules": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    },
    "redaction_rules": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    },
    "forbidden_actions": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    }
  },
  "additionalProperties": false
}
