{
  "openapi": "3.1.0",
  "info": {
    "title": "ADASM Energy Efficiency Simulator API",
    "version": "1.0.0",
    "description": "API pubblica e deterministica per simulazioni preliminari di efficienza energetica, fotovoltaico e accumulo."
  },
  "servers": [{ "url": "https://hub-energetico.vercel.app" }],
  "paths": {
    "/api/energy-simulator": {
      "get": {
        "operationId": "getSimulatorInformation",
        "summary": "Restituisce informazioni e un esempio di utilizzo",
        "responses": { "200": { "description": "Informazioni API" } }
      },
      "post": {
        "operationId": "simulateEnergyEfficiency",
        "summary": "Simula fotovoltaico, accumulo, autoconsumo, risparmio e payback",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/Scenario" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Simulazione completata",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SimulationResponse" } } }
          },
          "400": { "description": "Dati non validi" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Scenario": {
        "type": "object",
        "properties": {
          "segment": { "type": "string", "enum": ["industria", "hotel", "condominio", "retail", "agricolo"], "default": "industria" },
          "solarTechnology": { "type": "string", "enum": ["silicon", "tandem"], "default": "silicon" },
          "annualDemandMwh": { "type": "number", "minimum": 10, "default": 420 },
          "solarKwp": { "type": "number", "minimum": 0, "default": 180 },
          "solarUnitCostEurKwp": { "type": "number", "minimum": 100, "default": 1080 },
          "batteryKwh": { "type": "number", "minimum": 0, "default": 240 },
          "flexibleLoads": { "type": "boolean", "default": true },
          "energyPriceEurKwh": { "type": "number", "minimum": 0.01, "default": 0.26 },
          "exportPriceEurKwh": { "type": "number", "minimum": 0, "default": 0.1 },
          "capexEur": { "type": "number", "minimum": 0 },
          "opexEurYear": { "type": "number", "minimum": 0, "default": 7600 }
        }
      },
      "SimulationResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "simulation": {
            "type": "object",
            "properties": {
              "scenario": { "$ref": "#/components/schemas/Scenario" },
              "results": {
                "type": "object",
                "properties": {
                  "productionMwh": { "type": "number" },
                  "coveragePercent": { "type": "number" },
                  "netSavingEurYear": { "type": "number" },
                  "paybackYears": { "type": ["number", "null"] },
                  "avoidedCo2TonsYear": { "type": "number" }
                }
              },
              "notice": { "type": "string" }
            }
          }
        }
      }
    }
  }
}

