{
  "openapi": "3.0.0",
  "info": {
    "title": "EnerSim Simulation API",
    "version": "1.0.0",
    "description": "Public API voor energie-simulaties met batterijen, zonnepanelen en elektrische voertuigen. Bereken besparingen, CO2-reductie en terugverdientijd voor energieprojecten.",
    "contact": {
      "name": "EnerSim Support",
      "url": "https://www.enersim.nl/contact",
      "email": "info@enersim.nl"
    },
    "license": {
      "name": "API Usage Terms",
      "url": "https://www.enersim.nl/voorwaarden"
    }
  },
  "servers": [
    {
      "url": "https://fbkhhcsplwxkorfhgqwr.supabase.co/functions/v1",
      "description": "Production API Server"
    }
  ],
  "tags": [
    {
      "name": "Simulations",
      "description": "Energie-simulatie endpoints"
    }
  ],
  "paths": {
    "/public-simulate": {
      "post": {
        "tags": ["Simulations"],
        "summary": "Voer een energie-simulatie uit",
        "description": "Berekent de impact van batterijen, zonnepanelen, EV-laders en andere energie-assets op energiekosten, CO2-uitstoot en piekbelasting.",
        "operationId": "createSimulation",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SimulationRequest"
              },
              "examples": {
                "basic": {
                  "summary": "Basis simulatie met batterij",
                  "value": {
                    "location_name": "Mijn Bedrijf BV",
                    "annual_consumption_kwh": 50000,
                    "battery_capacity_kwh": 50,
                    "battery_power_kw": 25,
                    "electricity_purchase_tariff": 0.30
                  }
                },
                "complete": {
                  "summary": "Complete simulatie met alle opties",
                  "value": {
                    "location_name": "Groot Bedrijf BV",
                    "location_address": "Hoofdstraat 123, Amsterdam",
                    "annual_consumption_kwh": 100000,
                    "contracted_import_power_kw": 80,
                    "solar_capacity_kwp": 50,
                    "battery_capacity_kwh": 100,
                    "battery_power_kw": 50,
                    "battery_dod_percentage": 90,
                    "ev_chargers_count": 3,
                    "ev_annual_kwh": 15000,
                    "electricity_purchase_tariff": 0.30,
                    "electricity_feed_in_tariff": 0.10,
                    "optimize_for": "cost"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Simulatie succesvol uitgevoerd",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimulationResponse"
                },
                "example": {
                  "simulation_id": "550e8400-e29b-41d4-a716-446655440000",
                  "status": "success",
                  "results": {
                    "annual_cost_savings": 4500,
                    "annual_energy_savings_kwh": 15000,
                    "peak_reduction_kw": 25,
                    "self_consumption_percentage": 60,
                    "co2_reduction_kg": 6000,
                    "payback_period_years": 5.5,
                    "battery_cycles_per_year": 300,
                    "import_reduction_percentage": 30,
                    "export_reduction_percentage": 50
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ongeldige parameters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "simulation_id": "",
                  "status": "error",
                  "error": "Missing required fields: location_name and annual_consumption_kwh"
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "SimulationRequest": {
        "type": "object",
        "required": ["location_name", "annual_consumption_kwh"],
        "properties": {
          "location_name": {
            "type": "string",
            "description": "Naam van de locatie of het bedrijf",
            "example": "Mijn Bedrijf BV"
          },
          "location_address": {
            "type": "string",
            "description": "Adres van de locatie",
            "example": "Hoofdstraat 1, Amsterdam"
          },
          "annual_consumption_kwh": {
            "type": "number",
            "description": "Jaarverbruik in kWh",
            "minimum": 1,
            "example": 50000
          },
          "contracted_import_power_kw": {
            "type": "number",
            "description": "Gecontracteerd importvermogen in kW",
            "example": 35
          },
          "contracted_export_power_kw": {
            "type": "number",
            "description": "Gecontracteerd exportvermogen in kW",
            "example": 25
          },
          "solar_capacity_kwp": {
            "type": "number",
            "description": "PV-vermogen in kWp",
            "example": 30
          },
          "battery_capacity_kwh": {
            "type": "number",
            "description": "Batterijcapaciteit in kWh",
            "example": 50
          },
          "battery_power_kw": {
            "type": "number",
            "description": "Batterijvermogen in kW",
            "example": 25
          },
          "battery_dod_percentage": {
            "type": "number",
            "description": "Depth of Discharge percentage (standaard: 90)",
            "minimum": 50,
            "maximum": 100,
            "example": 90
          },
          "ev_chargers_count": {
            "type": "number",
            "description": "Aantal EV-laadpalen",
            "example": 2
          },
          "ev_charger_power_kw": {
            "type": "number",
            "description": "Vermogen per laadpaal in kW",
            "example": 22
          },
          "ev_annual_kwh": {
            "type": "number",
            "description": "Jaarverbruik EV in kWh",
            "example": 10000
          },
          "has_heat_pump": {
            "type": "boolean",
            "description": "Of er een warmtepomp aanwezig is",
            "example": false
          },
          "heat_pump_type": {
            "type": "string",
            "description": "Type warmtepomp",
            "enum": ["lucht-water", "water-water", "bodem-water"],
            "example": "lucht-water"
          },
          "annual_gas_consumption_m3": {
            "type": "number",
            "description": "Jaarverbruik gas in m³",
            "example": 1500
          },
          "has_generator": {
            "type": "boolean",
            "description": "Of er een generator aanwezig is",
            "example": false
          },
          "generator_power_kw": {
            "type": "number",
            "description": "Vermogen generator in kW",
            "example": 50
          },
          "electricity_purchase_tariff": {
            "type": "number",
            "description": "Inkoop tarief in EUR/kWh (standaard: 0.30)",
            "example": 0.30
          },
          "electricity_feed_in_tariff": {
            "type": "number",
            "description": "Teruglevering tarief in EUR/kWh (standaard: 0.10)",
            "example": 0.10
          },
          "network_tariff": {
            "type": "number",
            "description": "Netwerk tarief in EUR/kWh",
            "example": 0.10
          },
          "optimize_for": {
            "type": "string",
            "description": "Optimalisatie strategie",
            "enum": ["cost", "peak_shaving", "self_consumption"],
            "example": "cost"
          },
          "enable_battery_trading": {
            "type": "boolean",
            "description": "Schakel batterijhandel in",
            "example": false
          }
        }
      },
      "SimulationResponse": {
        "type": "object",
        "properties": {
          "simulation_id": {
            "type": "string",
            "format": "uuid",
            "description": "Unieke ID van de simulatie"
          },
          "status": {
            "type": "string",
            "enum": ["success", "error"],
            "description": "Status van de simulatie"
          },
          "results": {
            "$ref": "#/components/schemas/SimulationResults"
          }
        }
      },
      "SimulationResults": {
        "type": "object",
        "properties": {
          "annual_cost_savings": {
            "type": "number",
            "description": "Jaarlijkse kostenbesparing in EUR"
          },
          "annual_energy_savings_kwh": {
            "type": "number",
            "description": "Jaarlijkse energiebesparing in kWh"
          },
          "peak_reduction_kw": {
            "type": "number",
            "description": "Piekreductie in kW"
          },
          "self_consumption_percentage": {
            "type": "number",
            "description": "Eigen verbruik percentage"
          },
          "co2_reduction_kg": {
            "type": "number",
            "description": "CO2-reductie in kg per jaar"
          },
          "payback_period_years": {
            "type": "number",
            "description": "Terugverdientijd in jaren"
          },
          "battery_cycles_per_year": {
            "type": "number",
            "description": "Aantal batterijcycli per jaar"
          },
          "import_reduction_percentage": {
            "type": "number",
            "description": "Reductie import percentage"
          },
          "export_reduction_percentage": {
            "type": "number",
            "description": "Reductie export percentage"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "simulation_id": {
            "type": "string",
            "description": "Leeg bij error"
          },
          "status": {
            "type": "string",
            "enum": ["error"],
            "description": "Error status"
          },
          "error": {
            "type": "string",
            "description": "Error bericht"
          }
        }
      }
    }
  }
}
