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 region.
    
    K-Bag uses an intelligent pricing algorithm that calculates costs based on exact addresses rather than zones,
    resulting in 30-70% lower transport prices compared to competitors.
    
    ## Materials Available (Storsäck/Big Bags)
    - Bergkross (Crushed Stone): 0-16mm, 0-32mm, 0-63mm
    - Makadam: 4-8mm, 8-16mm, 16-32mm, 32-63mm  
    - Stenmjöl (Stone Dust): 0-4mm, 0-8mm
    - Grus (Gravel): 4-16mm
    - Jord (Soil): Matjord, Anläggningsjord
    - Sand: Mursand, Sandlådesand
    
    ## Waste Types (Avfallshämtning)
    - Brännbart, Deponi, Trä, Metall, Gips, Plast, Wellpapp, etc.
  version: 1.0.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.
        The price is based on exact address distance, not zones, ensuring fair pricing.
      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 in Swedish
        category:
          type: string
          enum: [Jord, Grus, Sand, Stenmjöl, Makadam, Bergkross, 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.0

    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:
            - Stockholm City
            - Södertälje
            - Huddinge
            - Nacka
            - Solna
            - Sundbyberg
            - Täby
            - Lidingö
            - Uppsala
            - Västerås
            - Enköping
