{
  "openapi": "3.1.0",
  "info": {
    "title": "Date deschise — resolver administrativ",
    "version": "2026-09-07-forexebug-deschis-v2.0",
    "description": "API publică pentru rezolvarea identificatorilor administrativi și verificarea ediției publicate. Valorile financiare din ediția curentă sunt un demonstrator modelat, nu observații Forexebug importate."
  },
  "servers": [
    { "url": "https://mariuscomper.uk/forexebug-deschis" }
  ],
  "paths": {
    "/api/resolve": {
      "get": {
        "summary": "Rezolvă un UAT după SIRUTA, CUI, QID, cod poștal sau nume",
        "parameters": [
          { "name": "q", "in": "query", "schema": { "type": "string" }, "description": "Fragment de nume, județ, CUI, SIRUTA, QID sau cod poștal" },
          { "name": "siruta", "in": "query", "schema": { "type": "string", "pattern": "^[0-9]{1,6}$" } },
          { "name": "cui", "in": "query", "schema": { "type": "string", "pattern": "^(?:RO)?[0-9]{2,10}$" } },
          { "name": "qid", "in": "query", "schema": { "type": "string", "pattern": "^Q[0-9]+$" } },
          { "name": "postal", "in": "query", "schema": { "type": "string", "pattern": "^[0-9]{6}$" } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 50, "default": 50 } }
        ],
        "responses": {
          "200": { "description": "Rezultatele potrivite", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ResolveResponse" } } } },
          "400": { "description": "Lipsește criteriul de căutare" }
        }
      }
    },
    "/api/checksum": {
      "get": {
        "summary": "Verifică cifra de control CUI",
        "parameters": [{ "name": "cui", "in": "query", "required": true, "schema": { "type": "string", "pattern": "^(?:RO)?[0-9]{2,10}$" } }],
        "responses": {
          "200": { "description": "Rezultatul verificării sintactice", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ChecksumResponse" } } } },
          "400": { "description": "CUI lipsă" }
        }
      }
    },
    "/api/health": {
      "get": {
        "summary": "Starea ediției publicate",
        "responses": { "200": { "description": "Statutul și numărul artefactelor", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HealthResponse" } } } } }
      }
    },
    "/api/quality.json": { "get": { "summary": "Raportul de calitate al identității și al seriei", "responses": { "200": { "description": "Raport JSON" } } } },
    "/api/use-cases.json": { "get": { "summary": "Catalogul celor 50 de utilizări", "responses": { "200": { "description": "Catalog JSON" } } } },
    "/api/openapi.json": { "get": { "summary": "Acest contract OpenAPI", "responses": { "200": { "description": "Document OpenAPI 3.1" } } } }
  },
  "components": {
    "schemas": {
      "UAT": {
        "type": "object",
        "required": ["s", "n", "j", "t", "dataStatus"],
        "properties": {
          "s": { "type": "string", "description": "SIRUTA" },
          "c": { "type": ["string", "null"], "description": "CUI/CIF, posibil lipsă" },
          "cuiValid": { "type": "boolean" },
          "qid": { "type": ["string", "null"] },
          "qurl": { "type": ["string", "null"], "format": "uri" },
          "n": { "type": "string", "description": "Denumire de căutare" },
          "no": { "type": "string", "description": "Denumire oficială" },
          "t": { "type": "string" },
          "td": { "type": "string" },
          "j": { "type": "string" },
          "ja": { "type": "string" },
          "ji": { "type": ["integer", "null"] },
          "iso": { "type": "string" },
          "r": { "type": "string" },
          "p": { "type": "integer" },
          "lat": { "type": ["number", "null"] },
          "lon": { "type": ["number", "null"] },
          "postal": { "type": ["string", "null"] },
          "address": { "type": "string" },
          "website": { "type": ["string", "null"], "format": "uri" },
          "email": { "type": ["string", "null"] },
          "phone": { "type": ["string", "null"] },
          "hasBudgetSeries": { "type": "boolean" },
          "dataStatus": { "type": "string", "enum": ["modelled-demonstrator", "identity-only"] }
        }
      },
      "ResolveResponse": {
        "type": "object",
        "required": ["dataset", "release", "count", "results"],
        "properties": {
          "dataset": { "type": "string", "const": "uats-index" },
          "release": { "type": "string" },
          "query": { "type": "object" },
          "count": { "type": "integer" },
          "results": { "type": "array", "items": { "$ref": "#/components/schemas/UAT" } }
        }
      },
      "ChecksumResponse": {
        "type": "object",
        "required": ["cui", "formatValid", "checksumValid"],
        "properties": {
          "cui": { "type": "string" },
          "formatValid": { "type": "boolean" },
          "checksumValid": { "type": "boolean" },
          "valid": { "type": "boolean" },
          "note": { "type": "string" }
        }
      },
      "HealthResponse": {
        "type": "object",
        "required": ["status", "release", "sourceStatus", "officialBudgetRowsIngested", "crosswalkEntities", "budgetEntities", "budgetRows"],
        "properties": {
          "status": { "type": "string", "enum": ["ok", "error"] },
          "release": { "type": "string" },
          "sourceStatus": { "type": "string", "const": "modelled-demonstrator" },
          "officialBudgetRowsIngested": { "type": "integer", "const": 0 },
          "crosswalkEntities": { "type": "integer" },
          "budgetEntities": { "type": "integer" },
          "budgetRows": { "type": "integer" },
          "identityQuality": { "type": "object" },
          "budgetSeries": { "type": "object" }
        }
      }
    }
  }
}
