{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://reversa.dev/schemas/screens/inventory.json",
  "title": "Screen Translator Internal Inventory",
  "description": "Inventário interno do Screen Translator. Lista cada unidade visual detectada no legado, com identidade estável e rastreabilidade ao código fonte. Salvo em _reversa_sdd/screens/inventory.json. Sobrescrito a cada execução.",
  "type": "object",
  "required": ["schemaVersion", "generatedAt", "sourcePlatform", "screens"],
  "properties": {
    "schemaVersion": {
      "type": "integer",
      "const": 1
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "producedBy": {
      "type": "string",
      "const": "screen-translator"
    },
    "sourcePlatform": {
      "type": "string",
      "description": "Slug da plataforma origem detectada (ex: cobol-ansi-tui, delphi-vcl, asp-classic, android-xml, ios-xib)."
    },
    "detectionConfidence": {
      "type": "string",
      "enum": ["confirmed", "inferred", "gap", "ambiguous"]
    },
    "screens": {
      "type": "array",
      "description": "Lista de telas detectadas no legado.",
      "items": {
        "type": "object",
        "required": ["id", "canonicalName", "legacyOrigin"],
        "properties": {
          "id": {
            "type": "string",
            "description": "Identificador único e estável dentro deste inventário (ex: SCR-0001)."
          },
          "canonicalName": {
            "type": "string",
            "description": "Nome canônico da tela usado em target_screens.md."
          },
          "legacyOrigin": {
            "type": "object",
            "required": ["file"],
            "properties": {
              "file": { "type": "string", "description": "Caminho relativo do arquivo legado." },
              "line": { "type": ["integer", "null"], "description": "Linha do arquivo, quando aplicável." },
              "paragraph": { "type": ["string", "null"], "description": "Nome do paragrafo COBOL, do form Delphi/VB6, da Activity Android, etc." }
            }
          },
          "kind": {
            "type": "string",
            "enum": [
              "tui-screen",
              "form",
              "page",
              "activity",
              "fragment",
              "view-controller",
              "modal",
              "dialog",
              "wizard-step",
              "menu",
              "list",
              "detail",
              "report",
              "raw"
            ],
            "description": "Tipo estrutural da tela. Use 'raw' quando o adapter não cobre o tipo."
          },
          "isCritical": {
            "type": "boolean",
            "description": "Marca telas críticas vs auxiliares (alimentado por reversa-detective quando disponível). Em modo híbrido, telas críticas tendem a ir para literal."
          },
          "matchesUiInventory": {
            "type": "boolean",
            "description": "true se a tela aparece em _reversa_sdd/ui/inventory.md."
          },
          "uiInventoryRef": {
            "type": ["string", "null"],
            "description": "Linha ou âncora correspondente em _reversa_sdd/ui/inventory.md."
          },
          "interpolations": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Variáveis dinâmicas detectadas (ex: '{{titular}}', '{{saldo}}')."
          },
          "transitions": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Próximas telas ou eventos disparados a partir desta."
          },
          "tokens": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Tokens do design-system referenciados (ex: 'color.cyan', 'typography.h1')."
          },
          "i18n": {
            "type": "object",
            "description": "Quando a tela tem catálogo de strings externo.",
            "properties": {
              "catalog": { "type": "string", "description": "Caminho do catálogo (ex: 'res/values/strings.xml', 'locale/pt_BR.po')." },
              "keysReferenced": { "type": "array", "items": { "type": "string" } }
            }
          }
        }
      }
    },
    "skipped": {
      "type": "object",
      "description": "Quando o legado não tem UI, este campo é preenchido e screens[] fica vazio.",
      "properties": {
        "reason": { "type": "string" },
        "emittedAt": { "type": "string", "format": "date-time" }
      }
    },
    "divergenceFromUiInventory": {
      "type": "object",
      "description": "Comparação contra _reversa_sdd/ui/inventory.md. Se divergencePercent > 10, o agente para e pede revisão (RF-05).",
      "properties": {
        "totalInUiInventory": { "type": "integer" },
        "totalInThisInventory": { "type": "integer" },
        "matched": { "type": "integer" },
        "missingInUiInventory": { "type": "array", "items": { "type": "string" } },
        "extraInUiInventory": { "type": "array", "items": { "type": "string" } },
        "divergencePercent": { "type": "number" }
      }
    }
  }
}
