{
  "openapi": "3.1.0",
  "info": {
    "title": "Bangkok Blazers booking API",
    "version": "1.0.0",
    "description": "Scooter rental in Bangkok. Read fleet and prices, check availability, get a quote and create a booking. Two ways to pay (pay_option): 'full' = the whole rent is paid online now, only the refundable deposit at pickup; 'cover' = the first day's rent is paid online now by card, the card is saved and the rest is charged to it automatically at the handover."
  },
  "servers": [
    {
      "url": "https://www.bangkokblazers.com/api"
    }
  ],
  "paths": {
    "/config": {
      "get": {
        "operationId": "getConfig",
        "summary": "Fleet, prices and booking settings",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Config"
                }
              }
            }
          }
        }
      }
    },
    "/availability": {
      "get": {
        "operationId": "getAvailability",
        "summary": "Free units per scooter and day",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "from": {
                      "type": "string"
                    },
                    "to": {
                      "type": "string"
                    },
                    "free": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "object",
                        "additionalProperties": {
                          "type": "integer"
                        }
                      },
                      "description": "vehicle class id -> date -> free units"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/quote": {
      "get": {
        "operationId": "getQuote",
        "summary": "Price and availability for one scooter and date range",
        "parameters": [
          {
            "name": "scooter_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "start_date",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "end_date",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "pickup_time",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^\\d{2}:\\d{2}$"
            },
            "description": "HH:MM Bangkok time, 09:00-17:00, default 10:00. Sundays by appointment only."
          },
          {
            "name": "return_time",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^\\d{2}:\\d{2}$"
            },
            "description": "HH:MM Bangkok time, 09:00-17:00, default = pickup_time"
          },
          {
            "name": "delivery",
            "in": "query",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1,
                2
              ]
            },
            "description": "0 shop pickup, 1 free delivery zone, 2 outside zone"
          },
          {
            "name": "protection",
            "in": "query",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            },
            "description": "Optional damage protection (Grand Filano 150 THB/day, NMAX 200 THB/day, at most 14 days per 28 days): renter pays at most 2,000 THB per damage"
          },
          {
            "name": "reducer",
            "in": "query",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            },
            "description": "Reducer on top of the protection (+100 THB/day): at most 1,000 THB per damage"
          },
          {
            "name": "pay_option",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "full",
                "cover"
              ]
            },
            "description": "full (default, whole rent online now) or cover (first day online now, card saved, rest charged at the handover)"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/bookings": {
      "post": {
        "operationId": "createBooking",
        "summary": "Book a scooter",
        "description": "Only call after the customer confirmed scooter, dates, price and pay_option, holds a valid motorcycle license and accepts the rental terms. Returns the booking reference and a payment_url (save the card, or prepay the first day). Give the customer the payment_url; the booking is confirmed once they complete it. Never enter payment details yourself.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BookingRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BookingCreated"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/bookings/status": {
      "get": {
        "operationId": "getBookingStatus",
        "summary": "Status of a booking",
        "parameters": [
          {
            "name": "ref",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "t",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Booking token from createBooking"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "Error": {
        "description": "Error",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "Scooter": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "cc": {
            "type": "integer"
          },
          "features": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "price_day": {
            "type": "integer"
          },
          "price_week": {
            "type": "integer"
          },
          "price_2week": {
            "type": "integer",
            "nullable": true,
            "description": "Price for 14 days (from 14 days on). Null if there is no 2-week rate."
          },
          "price_month": {
            "type": "integer",
            "description": "Price for 28 days"
          },
          "security_deposit": {
            "type": "integer"
          },
          "units": {
            "type": "integer"
          }
        }
      },
      "Config": {
        "type": "object",
        "properties": {
          "scooters": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Scooter"
            }
          },
          "settings": {
            "type": "object"
          },
          "today": {
            "type": "string"
          }
        }
      },
      "Quote": {
        "type": "object",
        "properties": {
          "scooter_id": {
            "type": "string",
            "description": "Vehicle class id from /api/config (e.g. city125, maxi155). Older single scooter ids are accepted and count as a wish."
          },
          "available": {
            "type": "boolean"
          },
          "units_free": {
            "type": "integer"
          },
          "days": {
            "type": "integer"
          },
          "rental": {
            "type": "integer",
            "description": "Rent incl. any peak season surcharge"
          },
          "peak_season_fee": {
            "type": "integer",
            "description": "Peak season surcharge included in rental (0 outside the season)"
          },
          "peak_season_days": {
            "type": "integer"
          },
          "delivery_fee": {
            "type": "integer"
          },
          "protection_fee": {
            "type": "integer"
          },
          "total": {
            "type": "integer"
          },
          "pay_now_online": {
            "type": "integer",
            "description": "Amount paid online now (whole rent with pay_option=full, first day's rent with pay_option=cover)"
          },
          "pay_at_pickup": {
            "type": "integer"
          },
          "security_deposit_at_pickup": {
            "type": "integer"
          },
          "currency": {
            "type": "string"
          }
        }
      },
      "BookingRequest": {
        "type": "object",
        "required": [
          "scooter_id",
          "start_date",
          "end_date",
          "name",
          "email",
          "phone",
          "licence_ok",
          "accept_terms",
          "pay_option"
        ],
        "properties": {
          "scooter_id": {
            "type": "string",
            "description": "Vehicle class id from /api/config (e.g. city125, maxi155). Older single scooter ids are accepted and count as a wish."
          },
          "start_date": {
            "type": "string",
            "format": "date"
          },
          "end_date": {
            "type": "string",
            "format": "date"
          },
          "pickup_time": {
            "type": "string",
            "pattern": "^\\d{2}:\\d{2}$",
            "description": "HH:MM Bangkok time, 09:00-17:00, default 10:00. Sundays by appointment only."
          },
          "return_time": {
            "type": "string",
            "pattern": "^\\d{2}:\\d{2}$",
            "description": "HH:MM, default = pickup_time"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9][0-9]{7,14}$",
            "description": "WhatsApp number with + and country code"
          },
          "whatsapp_ok": {
            "type": "boolean"
          },
          "lang": {
            "type": "string",
            "enum": [
              "en",
              "de",
              "th",
              "fr",
              "es",
              "ru",
              "zh",
              "ko",
              "ja"
            ]
          },
          "delivery": {
            "type": "integer",
            "enum": [
              0,
              1,
              2
            ]
          },
          "hotel": {
            "type": "string"
          },
          "protection": {
            "type": "boolean",
            "description": "Optional damage protection"
          },
          "notes": {
            "type": "string"
          },
          "licence_ok": {
            "type": "boolean",
            "const": true
          },
          "accept_terms": {
            "type": "boolean",
            "const": true
          },
          "reducer": {
            "type": "boolean",
            "description": "Reducer, only together with protection"
          },
          "pay_option": {
            "type": "string",
            "enum": [
              "full",
              "cover"
            ],
            "description": "full = whole rent online now (free cancellation up to 24 h before with full refund, later or no-show one day's rent kept, rest refunded); cover = first day online now by card, card saved, rest charged at the handover (free cancellation up to 24 h before with full refund, later or no-show the first day is kept)"
          },
          "wish": {
            "type": "string",
            "description": "Optional color/model wish: a scooter id from fleet in /api/config. Not guaranteed."
          }
        }
      },
      "BookingCreated": {
        "type": "object",
        "properties": {
          "ref": {
            "type": "string"
          },
          "token": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "confirmed"
            ]
          },
          "payment_url": {
            "type": [
              "string",
              "null"
            ],
            "description": "Stripe payment page (whole rent or first day). The customer must open it within 30 minutes."
          },
          "status_url": {
            "type": "string"
          },
          "hold_expires_at": {
            "type": [
              "string",
              "null"
            ],
            "description": "Until then the scooter is held for the customer; unpaid bookings expire."
          },
          "total": {
            "type": "integer"
          },
          "pay_now": {
            "type": "integer",
            "description": "Paid online now (first day's rent, deducted from the rent)"
          },
          "pay_at_pickup": {
            "type": "integer"
          },
          "security_deposit": {
            "type": "integer"
          },
          "currency": {
            "type": "string"
          }
        }
      }
    }
  }
}
