{
  "openapi": "3.0.3",
  "info": {
    "title": "CyberBaseline B2B API v1",
    "description": "API-ul public securizat CyberBaseline oferă acces B2B la scorurile pe 5 piloni, indicatorii financiari și cibernetici și conformitatea GDPR pentru toate firmele active din România.",
    "version": "1.0.0",
    "contact": {
      "name": "Echipa Suport Integrări CyberBaseline",
      "email": "api@cyberbaseline.ro",
      "url": "https://cyberbaseline.ro/dashboard/api-keys"
    }
  },
  "servers": [
    {
      "url": "https://cyberbaseline.ro",
      "description": "Server Producție"
    },
    {
      "url": "http://localhost:5173",
      "description": "Mediu Dezvoltare Local"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/endpoints/v1/company/{cui}": {
      "get": {
        "summary": "Obține profilul complet al companiei și Scorul pe 5 Piloni",
        "description": "Returnează profilul companiei identificată prin CUI, incluzând Scorul Financiar, Amprenta Digitală, Expunerea Cibernetică, Conformitatea GDPR și Sinteza AI Executivă.",
        "operationId": "getCompanyProfileByCui",
        "parameters": [
          {
            "name": "cui",
            "in": "path",
            "required": true,
            "description": "CUI-ul firmei (ex. RO13838383 sau 13838383)",
            "schema": {
              "type": "string",
              "example": "RO13838383"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Profilul companiei a fost returnat cu succes.",
            "headers": {
              "X-RateLimit-Limit": {
                "schema": { "type": "integer" },
                "description": "Limita lunară totală de cereri permise"
              },
              "X-RateLimit-Remaining": {
                "schema": { "type": "integer" },
                "description": "Numărul de cereri rămase în luna curentă"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompanyV1Response"
                }
              }
            }
          },
          "401": {
            "description": "Autentificare eșuată sau cheie API invalidă/revocată.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "429": {
            "description": "Limita de rate-limiting lunară a fost depășită.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "404": {
            "description": "Compania nu a fost găsită.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/endpoints/v1/enrich": {
      "post": {
        "summary": "Îmbogățire Batch Listă de CUI-uri",
        "description": "Acceptă o listă de până la 50 de CUI-uri și returnează un rezumat al scorurilor pe cei 5 piloni pentru fiecare firmă.",
        "operationId": "enrichCuiBatch",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["cuis"],
                "properties": {
                  "cuis": {
                    "type": "array",
                    "items": { "type": "string" },
                    "example": ["RO13838383", "RO12345678", "RO1623456"]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rezultatele de îmbogățire batch au fost generate cu succes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EnrichV1Response"
                }
              }
            }
          },
          "400": {
            "description": "Cerere invalidă (ex. corp invalid sau peste 50 de CUI-uri).",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Cheie API lipsă sau invalidă."
          },
          "429": {
            "description": "Limită de rate-limiting depășită."
          }
        }
      }
    },
    "/endpoints/v1/benchmark": {
      "get": {
        "summary": "Punctaj Comparativ pe Industrie",
        "description": "Returnează mediile pilonilor, percentilele (P90, P75, P50, P25) și distribuția riscului pentru un sector sau cod CAEN.",
        "operationId": "getIndustryBenchmark",
        "parameters": [
          {
            "name": "industry",
            "in": "query",
            "required": false,
            "description": "Numele industriei sau sectorului",
            "schema": { "type": "string", "example": "Cybersecurity & Software" }
          },
          {
            "name": "caenCode",
            "in": "query",
            "required": false,
            "description": "Cod CAEN cu 4 cifre",
            "schema": { "type": "string", "example": "6201" }
          }
        ],
        "responses": {
          "200": {
            "description": "Statisticele comparative de benchmark au fost calculate.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BenchmarkV1Response"
                }
              }
            }
          },
          "401": {
            "description": "Neautorizat."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "APIKey",
        "description": "Introduceți cheia API B2B generată în portalul /dashboard/api-keys (ex. `cb_live_...`)"
      }
    },
    "schemas": {
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": false },
          "error": { "type": "string", "example": "Mesaj detaliat eroare" }
        }
      },
      "CompanyV1Response": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": true },
          "data": {
            "type": "object",
            "properties": {
              "cui": { "type": "string", "example": "RO13838383" },
              "name": { "type": "string", "example": "FAN Courier Express S.R.L." },
              "industry": { "type": "string", "example": "Curierat & Logistică" },
              "scoreSummary": {
                "type": "object",
                "properties": {
                  "cyberBaselineScore": { "type": "number", "example": 88 },
                  "financialScore": { "type": "number", "example": 90 },
                  "digitalScore": { "type": "number", "example": 85 },
                  "securityScore": { "type": "number", "example": 84 },
                  "complianceScore": { "type": "number", "example": 92 },
                  "operationalScore": { "type": "number", "example": 89 }
                }
              }
            }
          }
        }
      },
      "EnrichV1Response": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": true },
          "totalProcessed": { "type": "integer", "example": 3 },
          "results": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "cui": { "type": "string" },
                "found": { "type": "boolean" },
                "name": { "type": "string" },
                "cyberBaselineScore": { "type": "number" }
              }
            }
          }
        }
      },
      "BenchmarkV1Response": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": true },
          "query": { "type": "object" },
          "metrics": {
            "type": "object",
            "properties": {
              "totalCompaniesInBenchmark": { "type": "integer" },
              "averageCyberBaselineScore": { "type": "number" },
              "percentileBreakdown": { "type": "object" }
            }
          }
        }
      }
    }
  }
}
