{
  "openapi": "3.1.0",
  "info": {
    "title": "K-Bag Transport Calculator API",
    "description": "API for calculating transport prices for construction material delivery and waste pickup in Stockholm County.\nK-Bag's public website is bilingual: Swedish is default and English pages are available with ?lng=en.\n\nK-Bag uses an intelligent pricing algorithm that calculates costs based on exact addresses rather than zones,\nresulting in on average 50% better transport prices compared to competitors.\n\n## Price Comparison (Storsäck Makadam 8-16mm, inkl. moms)\n- Traditional supplier (zone pricing): 2 807 kr total\n- Online supplier (flat price): 2 650 kr total\n- Quote-based supplier: 1 423 kr + unknown freight\n- K-Bag (address-based): from 1 534 kr total — save 31-42%\n\n## Materials Available (Storsäck/Big Bags)\n- Jord (Soil): Gräsmattejord A (Lawn soil), Växtjord A Plant (Planting soil), Rabattjord\n- Bergkross (Crushed Rock): 0-16mm, 0-32mm, 0-63mm\n- Makadam: 4-8mm, 8-16mm, 16-32mm, 32-63mm  \n- Stenmjöl (Stone Dust): 0-4mm, 0-8mm\n- Grus (Gravel): Singel NK 8/16, Singel NK 4/8, 0/4 Natur grus (Natural gravel), Rörgravsgrus 0-8mm (Pipe bedding gravel)\n- Material landing pages: /storsack/{material}/{kommun}; English alternates use ?lng=en.\n\n## Waste Types (Avfallshämtning)\n- Brännbart/Combustible, Deponi/Landfill, Trä/Wood, Metall/Metal, Gips/Gypsum, Fyllnadsmassor/Fill material, Konstruktion/Construction, Osorterat/Unsorted.\n- Waste pickup landing pages: /avfallshamtning/{kommun}; English alternates use ?lng=en.\n",
    "version": "1.2.0",
    "contact": {
      "name": "K-Bag Support",
      "email": "info@kbag.se",
      "url": "https://kbag.se"
    }
  },
  "servers": [
    {
      "url": "https://xahbnzmfwbkpvfemsvmk.supabase.co/functions/v1",
      "description": "Production API"
    }
  ],
  "paths": {
    "/calculate-delivery-price": {
      "post": {
        "operationId": "calculateDeliveryPrice",
        "summary": "Calculate transport price for delivery",
        "description": "Calculates the transport price per bag for delivering construction materials to a specified address.\nThe price is based on exact address distance, not zones, ensuring fair pricing.\nK-Bag's total price (material + transport) is on average 50% better than competitors.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "address",
                  "quantity"
                ],
                "properties": {
                  "address": {
                    "type": "string",
                    "description": "Full delivery address including street, postal code, and city",
                    "example": "Storgatan 1, 111 22 Stockholm"
                  },
                  "quantity": {
                    "type": "integer",
                    "description": "Number of bags to deliver",
                    "example": 3
                  },
                  "order_type": {
                    "type": "string",
                    "enum": [
                      "delivery",
                      "pickup"
                    ],
                    "description": "Type of order - delivery for materials, pickup for waste",
                    "default": "delivery"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful price calculation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "transport_price_per_bag": {
                      "type": "number",
                      "description": "Transport price per bag in SEK"
                    },
                    "total_transport_price": {
                      "type": "number",
                      "description": "Total transport price for all bags in SEK"
                    },
                    "distance_km": {
                      "type": "number",
                      "description": "Distance from depot to delivery address"
                    },
                    "is_within_service_area": {
                      "type": "boolean",
                      "description": "Whether the address is within the 70km service radius"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Product": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "Product name, usually Swedish source name with English public translations available on kbag.se via ?lng=en"
          },
          "category": {
            "type": "string",
            "enum": [
              "Jord",
              "Grus",
              "Krossprodukter",
              "Makadam",
              "Bergkross",
              "Stenmjöl",
              "Avfallshämtning"
            ]
          },
          "price_sek": {
            "type": "number",
            "description": "Product price per bag in SEK"
          },
          "volume_m3": {
            "type": "number",
            "description": "Volume per bag in cubic meters",
            "default": 1
          }
        }
      },
      "ServiceArea": {
        "type": "object",
        "properties": {
          "center": {
            "type": "object",
            "properties": {
              "address": {
                "type": "string",
                "example": "Smista Allé 12, 141 74 Segeltorp"
              },
              "lat": {
                "type": "number",
                "example": 59.2445
              },
              "lng": {
                "type": "number",
                "example": 17.8234
              }
            }
          },
          "radius_km": {
            "type": "number",
            "example": 70
          },
          "regions": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": [
              "Botkyrka",
              "Danderyd",
              "Haninge",
              "Huddinge",
              "Järfälla",
              "Lidingö",
              "Nacka",
              "Nykvarn",
              "Salem",
              "Sigtuna",
              "Sollentuna",
              "Solna",
              "Stockholm",
              "Sundbyberg",
              "Södertälje",
              "Tyresö",
              "Täby",
              "Upplands-Bro",
              "Upplands Väsby",
              "Vallentuna",
              "Vaxholm",
              "Värmdö",
              "Österåker"
            ]
          }
        }
      }
    }
  }
}
