{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:awoooi:source-control-ref-detail-diff-v1",
  "title": "AWOOOI Source Control Ref Detail Diff (v1)",
  "description": "針對 Gitea / GitHub refs-blocked repo 保存 branch/tag 層級 read-only diff 明細。",
  "type": "object",
    "required": [
      "schema_version",
      "status",
      "date",
      "default_mode",
      "ignored_branches",
      "repo_count",
      "repos"
    ],
  "properties": {
    "schema_version": {
      "const": "source_control_ref_detail_diff_v1"
    },
    "status": {
      "type": "string",
      "enum": ["draft_blocked"]
    },
    "date": {
      "type": "string"
    },
    "default_mode": {
      "type": "string",
      "enum": ["read_only_diff"]
    },
    "ignored_branches": {
      "type": "array",
      "items": {"type": "string"}
    },
    "repo_count": {
      "type": "integer",
      "minimum": 0
    },
    "repos": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "repo_key",
          "repo_path",
          "gitea_remote",
          "github_remote",
          "gitea_url_redacted",
          "github_url_redacted",
          "gitea_repo",
          "github_repo",
          "status",
          "blocking_reason",
          "branch_diff",
          "tag_diff",
          "still_forbidden"
        ],
        "properties": {
          "repo_key": {"type": "string"},
          "repo_path": {"type": "string"},
          "gitea_remote": {"type": "string"},
          "github_remote": {"type": "string"},
          "gitea_url_redacted": {"type": "string"},
          "github_url_redacted": {"type": "string"},
          "gitea_repo": {"type": "string"},
          "github_repo": {"type": "string"},
          "status": {
            "type": "string",
            "enum": ["blocked", "verified", "probe_failed"]
          },
          "blocking_reason": {"type": "string"},
          "branch_diff": {"$ref": "#/$defs/refDiff"},
          "tag_diff": {"$ref": "#/$defs/refDiff"},
          "still_forbidden": {
            "type": "array",
            "items": {"type": "string"}
          }
        },
        "additionalProperties": false
      }
    }
  },
  "$defs": {
    "refItem": {
      "type": "object",
      "required": ["name", "sha"],
      "properties": {
        "name": {"type": "string"},
        "sha": {"type": "string"}
      },
      "additionalProperties": false
    },
    "refMismatch": {
      "type": "object",
      "required": ["name", "gitea_sha", "github_sha"],
      "properties": {
        "name": {"type": "string"},
        "gitea_sha": {"type": "string"},
        "github_sha": {"type": "string"}
      },
      "additionalProperties": false
    },
    "refDiff": {
      "type": "object",
      "required": [
        "gitea_count",
        "github_count",
        "only_gitea_count",
        "only_github_count",
        "sha_mismatch_count",
        "matching_count",
        "only_gitea",
        "only_github",
        "sha_mismatch",
        "matching"
      ],
      "properties": {
        "gitea_count": {"type": "integer", "minimum": 0},
        "github_count": {"type": "integer", "minimum": 0},
        "only_gitea_count": {"type": "integer", "minimum": 0},
        "only_github_count": {"type": "integer", "minimum": 0},
        "sha_mismatch_count": {"type": "integer", "minimum": 0},
        "matching_count": {"type": "integer", "minimum": 0},
        "only_gitea": {
          "type": "array",
          "items": {"$ref": "#/$defs/refItem"}
        },
        "only_github": {
          "type": "array",
          "items": {"$ref": "#/$defs/refItem"}
        },
        "sha_mismatch": {
          "type": "array",
          "items": {"$ref": "#/$defs/refMismatch"}
        },
        "matching": {
          "type": "array",
          "items": {"$ref": "#/$defs/refItem"}
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
