{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pkg.shecan.ir/api/v1/schema.json",
  "title": "pkg.shecan.ir read-only API, version 1",
  "description": "Static JSON generated from catalog/mirrors.yaml on every deploy. Within v1 fields are only added; a removed or redefined field gets /api/v2/. Mirror ids are stable. Fields ending in _fa are Persian.",
  "$defs": {
    "audit": {
      "type": "object",
      "required": ["group", "mirror", "url"],
      "properties": {
        "group": { "type": "string", "description": "Group id in the audit's summary.json (pkg-audit/summary@1)." },
        "mirror": { "type": "string", "description": "This mirror's name inside that group." },
        "url": { "type": "string", "description": "The group's section on audit.shecan.ir." }
      }
    },
    "record": {
      "type": "object",
      "required": ["id", "name", "category", "ecosystem", "upstream", "urls", "clients", "keywords", "description", "limitations", "status_key", "audit", "links"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9-]+$" },
        "name": { "type": "string" },
        "category": { "enum": ["language", "container", "os", "vendor", "tools"] },
        "ecosystem": { "type": "string" },
        "upstream": { "type": "string" },
        "urls": { "type": "array", "items": { "type": "string" } },
        "clients": { "type": "array", "items": { "type": "string" } },
        "keywords": { "type": "array", "items": { "type": "string" } },
        "description": { "type": "string" },
        "limitations": { "type": "array", "items": { "type": "string" } },
        "status_key": { "type": "string", "description": "Key of this mirror in https://pkg.shecan.ir/status.json `services` (up/down, checked every minute)." },
        "audit": { "type": "array", "items": { "$ref": "#/$defs/audit" } },
        "links": {
          "type": "object",
          "required": ["guide", "markdown", "json"],
          "properties": { "guide": { "type": "string" }, "markdown": { "type": "string" }, "json": { "type": "string" } }
        }
      }
    },
    "step": {
      "type": "object",
      "required": ["clients", "scope", "role", "platforms", "lang", "code", "verification", "label_fa", "section_fa"],
      "properties": {
        "clients": { "type": "array", "items": { "type": "string" } },
        "scope": { "enum": ["temporary", "persistent", "project"] },
        "role": { "enum": ["command", "config", "backup", "reset", "verify", "example"], "description": "reset undoes the change; verify checks it." },
        "platforms": { "type": "array", "items": { "enum": ["linux", "macos", "windows"] } },
        "variant": { "type": "string" },
        "file": { "type": "string", "description": "For role config: the file to write or merge into." },
        "paths": { "type": "object", "additionalProperties": { "type": "string" }, "description": "The file's path where it differs per platform." },
        "lang": { "type": "string" },
        "code": { "type": "string", "description": "Exactly what the guide's copy button copies." },
        "verification": { "enum": ["automated", "manual", "none"], "description": "automated: run against the live mirror in a disposable container on every catalog change; manual: checked another way (see verification_note_fa); none: an illustration." },
        "verification_note_fa": { "type": "string" },
        "label_fa": { "type": "string" },
        "section_fa": { "type": "string" }
      }
    }
  },
  "oneOf": [
    {
      "title": "/api/v1/mirrors.json",
      "type": "object",
      "required": ["api_version", "mirrors"],
      "properties": { "api_version": { "const": 1 }, "mirrors": { "type": "array", "items": { "$ref": "#/$defs/record" } } }
    },
    {
      "title": "/api/v1/mirrors/{id}.json",
      "type": "object",
      "required": ["api_version", "mirror"],
      "properties": {
        "api_version": { "const": 1 },
        "mirror": {
          "allOf": [
            { "$ref": "#/$defs/record" },
            {
              "type": "object",
              "required": ["title_fa", "summary_fa", "notes_fa", "endpoints", "steps"],
              "properties": {
                "endpoints": { "type": "array", "items": { "type": "object", "required": ["label_fa", "url"] } },
                "image_prefixes": { "type": "array" },
                "steps": { "type": "array", "items": { "$ref": "#/$defs/step" } }
              }
            }
          ]
        }
      }
    },
    {
      "title": "/api/v1/ (index.json)",
      "type": "object",
      "required": ["api_version", "mirrors_count", "links", "audit"]
    }
  ]
}
