{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:awoooi:source-control-workflow-secret-name-export-request-v1",
  "title": "Source Control Workflow / Secret Name Export Request v1",
  "description": "定義 S4.3 後續需要 owner 或只讀 API 補齊的 workflow / webhook / runner / deploy key / branch protection / secret 名稱 redacted export request。此 schema 只允許名稱與 metadata，不允許 secret value。",
  "type": "object",
  "required": [
    "schema_version",
    "status",
    "date",
    "mode",
    "runtime_execution_authorized",
    "source_contract",
    "source_indexes",
    "summary",
    "export_lanes",
    "repo_export_requests",
    "acceptance_rules",
    "redaction_rules",
    "forbidden_actions"
  ],
  "properties": {
    "schema_version": {
      "const": "source_control_workflow_secret_name_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": "source_control_workflow_secret_name_inventory_v1"
    },
    "source_indexes": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    },
    "summary": {
      "type": "object",
      "required": [
        "candidate_repo_count",
        "in_scope_request_count",
        "external_scope_review_count",
        "export_request_count",
        "export_lane_count",
        "webhook_export_request_repo_count",
        "runner_export_request_repo_count",
        "deploy_key_export_request_repo_count",
        "branch_protection_codeowners_export_request_repo_count",
        "repository_secret_name_parity_export_request_repo_count",
        "secret_value_collection_allowed",
        "write_token_allowed",
        "runtime_actions_authorized",
        "action_buttons_allowed"
      ],
      "properties": {
        "candidate_repo_count": {"type": "integer", "minimum": 0},
        "in_scope_request_count": {"type": "integer", "minimum": 0},
        "external_scope_review_count": {"type": "integer", "minimum": 0},
        "export_request_count": {"type": "integer", "minimum": 0},
        "export_lane_count": {"type": "integer", "minimum": 0},
        "webhook_export_request_repo_count": {"type": "integer", "minimum": 0},
        "runner_export_request_repo_count": {"type": "integer", "minimum": 0},
        "deploy_key_export_request_repo_count": {"type": "integer", "minimum": 0},
        "branch_protection_codeowners_export_request_repo_count": {"type": "integer", "minimum": 0},
        "repository_secret_name_parity_export_request_repo_count": {"type": "integer", "minimum": 0},
        "secret_value_collection_allowed": {"type": "boolean", "const": false},
        "write_token_allowed": {"type": "boolean", "const": false},
        "runtime_actions_authorized": {"type": "boolean", "const": false},
        "action_buttons_allowed": {"type": "boolean", "const": false}
      },
      "additionalProperties": false
    },
    "export_lanes": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "lane_id",
          "title",
          "request_status",
          "allowed_fields",
          "forbidden_fields",
          "accepted_producer_modes",
          "acceptance_gate",
          "execution_authorized"
        ],
        "properties": {
          "lane_id": {"type": "string"},
          "title": {"type": "string"},
          "request_status": {
            "type": "string",
            "enum": ["waiting_owner_or_readonly_export"]
          },
          "allowed_fields": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "forbidden_fields": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "accepted_producer_modes": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "acceptance_gate": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "execution_authorized": {
            "type": "boolean",
            "const": false
          }
        },
        "additionalProperties": false
      }
    },
    "repo_export_requests": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "repo_key",
          "github_repo",
          "source_key",
          "scope_status",
          "risk",
          "request_state",
          "requested_lanes",
          "owner_export_required",
          "read_only_api_allowed",
          "write_api_allowed",
          "secret_value_allowed",
          "acceptance_notes",
          "still_forbidden"
        ],
        "properties": {
          "repo_key": {"type": "string"},
          "github_repo": {"type": "string"},
          "source_key": {"type": "string"},
          "scope_status": {
            "type": "string",
            "enum": ["in_scope", "external_scope_review"]
          },
          "risk": {
            "type": "string",
            "enum": ["LOW", "MEDIUM", "HIGH"]
          },
          "request_state": {
            "type": "string",
            "enum": [
              "waiting_owner_export",
              "waiting_scope_review"
            ]
          },
          "requested_lanes": {
            "type": "array",
            "items": {"type": "string"}
          },
          "owner_export_required": {"type": "boolean"},
          "read_only_api_allowed": {"type": "boolean"},
          "write_api_allowed": {
            "type": "boolean",
            "const": false
          },
          "secret_value_allowed": {
            "type": "boolean",
            "const": false
          },
          "acceptance_notes": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "still_forbidden": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          }
        },
        "additionalProperties": false
      }
    },
    "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
}
