{
  "openapi": "3.1.0",
  "info": {
    "title": "Island Bookings Booking API",
    "version": "0.1.0",
    "description": "JSON API for the public booking flow: search locations, search trips, build a cart, capture customer details, create a booking, and initiate payment. Read-only endpoints (locations, search) are implemented; cart/customer/booking/payment endpoints are reserved and currently return 501 Not Implemented.",
    "contact": {
      "name": "Island Bookings"
    }
  },
  "servers": [
    {
      "url": "https://www.gilibookings.com",
      "description": "gilibookings"
    },
    {
      "url": "https://www.gilitickets.com",
      "description": "gilitickets"
    },
    {
      "url": "https://www.fiji-bookings.com",
      "description": "fijibookings"
    },
    {
      "url": "https://www.seychellesbookings.com",
      "description": "seychellesbookings"
    },
    {
      "url": "https://www.stmartinbookings.com",
      "description": "stmartinbookings"
    },
    {
      "url": "https://www.virginbookings.com",
      "description": "virginbookings"
    },
    {
      "url": "https://www.samuibookings.com",
      "description": "samuibookings"
    }
  ],
  "tags": [
    {"name": "discovery", "description": "Static reference data"},
    {"name": "search", "description": "Trip availability search"},
    {"name": "cart", "description": "Shopping cart (session-bound, requires cookies)"},
    {"name": "booking", "description": "Order creation"},
    {"name": "payment", "description": "Payment initiation and status"}
  ],
  "paths": {
    "/book/api/locations": {
      "get": {
        "tags": ["discovery"],
        "summary": "List bookable locations",
        "description": "Returns the hierarchy of pickup/dropoff locations available for fastboat/ferry/transfer search. IDs returned here are the valid values for the `from` and `to` parameters of `/book/api/search`.",
        "operationId": "listLocations",
        "responses": {
          "200": {
            "description": "List of locations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "locations": {
                      "type": "array",
                      "items": {"$ref": "#/components/schemas/Location"}
                    }
                  },
                  "required": ["locations"]
                }
              }
            }
          }
        }
      }
    },
    "/book/api/search": {
      "get": {
        "tags": ["search"],
        "summary": "Search trip availability",
        "description": "Search for available fastboat/ferry trips between two locations on a given date. Returns availability records that can be added to the cart via `/book/api/cart-add`.",
        "operationId": "searchTrips",
        "parameters": [
          {"name": "from", "in": "query", "required": true, "description": "Origin location id (from `/book/api/locations`).", "schema": {"type": "string"}},
          {"name": "to", "in": "query", "required": true, "description": "Destination location id.", "schema": {"type": "string"}},
          {"name": "departure", "in": "query", "required": true, "description": "Departure date in the site's short date format (e.g. dd-MM-yyyy).", "schema": {"type": "string"}},
          {"name": "return", "in": "query", "required": false, "description": "Return date for round-trip; omit for one-way.", "schema": {"type": "string"}},
          {"name": "type", "in": "query", "required": false, "description": "Trip type.", "schema": {"type": "string", "enum": ["one_way", "return", "island_hopping"], "default": "one_way"}},
          {"name": "adults", "in": "query", "required": false, "description": "Adult passengers. A party needs at least one adult or senior: children and infants cannot travel alone (`400` `At least one adult is required`).", "schema": {"type": "integer", "minimum": 0, "default": 1}},
          {"name": "children", "in": "query", "required": false, "schema": {"type": "integer", "minimum": 0, "default": 0}},
          {"name": "infants", "in": "query", "required": false, "schema": {"type": "integer", "minimum": 0, "default": 0}},
          {"name": "seniors", "in": "query", "required": false, "schema": {"type": "integer", "minimum": 0, "default": 0}},
          {"name": "page", "in": "query", "required": false, "schema": {"type": "integer", "minimum": 0, "default": 0}},
          {"name": "sort", "in": "query", "required": false, "schema": {"type": "string", "enum": ["price_asc", "price_desc", "departure_asc", "departure_desc"]}}
        ],
        "responses": {
          "200": {
            "description": "Search results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "results": {"type": "array", "items": {"$ref": "#/components/schemas/Availability"}},
                    "page": {"type": "integer"},
                    "total": {
                      "type": "integer"
                    },
                    "return_results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Availability"
                      },
                      "description": "Return-leg results when `type=return` and `return` is provided."
                    },
                    "return_total": {
                      "type": "integer",
                      "description": "Return-leg total when `type=return` and `return` is provided."
                    },
                    "reason": {
                      "type": "string",
                      "description": "Set when a search type is disabled or no boat routes exist between `from` and `to`."
                    }
                  },
                  "required": ["results"]
                }
              }
            }
          },
          "400": {"$ref": "#/components/responses/Error"}
        }
      }
    },
    "/book/api/cart-add": {
      "post": {
        "tags": ["cart"],
        "summary": "Add an availability to the cart",
        "description": "Adds a trip (and optional return trip) to the session cart. The cart is bound to the request session cookie. **Not yet implemented.**",
        "operationId": "addToCart",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "idavailability": {"type": "integer", "description": "Availability id from search results"},
                  "return_idavailability": {"type": "integer", "description": "Optional return availability"},
                  "adults": {"type": "integer", "minimum": 0, "default": 1, "description": "A party needs at least one adult or senior; otherwise `400` `At least one adult is required`."},
                  "children": {"type": "integer"},
                  "infants": {"type": "integer"},
                  "seniors": {"type": "integer"}
                },
                "required": ["idavailability"]
              }
            }
          }
        },
        "responses": {
          "200": {"$ref": "#/components/responses/Cart"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "501": {"$ref": "#/components/responses/NotImplemented"}
        },
        "security": [{"oauth2_client_credentials": ["book:api"]}]
      }
    },
    "/book/api/cart": {
      "get": {
        "tags": ["cart"],
        "summary": "Get current cart",
        "operationId": "getCart",
        "responses": {
          "200": {"$ref": "#/components/responses/Cart"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "501": {"$ref": "#/components/responses/NotImplemented"}
        },
        "security": [{"oauth2_client_credentials": ["book:api"]}]
      }
    },
    "/book/api/customer": {
      "post": {
        "tags": ["cart"],
        "summary": "Set customer details on the cart",
        "operationId": "setCustomer",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {"$ref": "#/components/schemas/Customer"}
            }
          }
        },
        "responses": {
          "200": {"$ref": "#/components/responses/Cart"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "501": {"$ref": "#/components/responses/NotImplemented"}
        },
        "security": [{"oauth2_client_credentials": ["book:api"]}]
      }
    },
    "/book/api/booking": {
      "post": {
        "tags": ["booking"],
        "summary": "Finalize cart into a booking (order)",
        "description": "Persists the session cart as an order. Returns the order reference (`idorder`). The order is created in `open` status; payment must be initiated separately via `/book/api/payment`.",
        "operationId": "createBooking",
        "responses": {
          "201": {
            "description": "Order created",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Order"}
              }
            }
          },
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "501": {"$ref": "#/components/responses/NotImplemented"}
        },
        "security": [{"oauth2_client_credentials": ["book:api"]}]
      }
    },
    "/book/api/payment": {
      "post": {
        "tags": ["payment"],
        "summary": "Initiate payment for an order",
        "operationId": "initiatePayment",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "idorder": {"type": "integer"},
                  "processor": {"type": "string", "enum": ["mollie", "buckaroo", "paypal", "emerchantpay"]}
                },
                "required": ["idorder", "processor"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payment initiated; redirect the user to `redirect_url`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "idorder": {"type": "integer"},
                    "redirect_url": {"type": "string", "format": "uri"},
                    "processor": {"type": "string"}
                  }
                }
              }
            }
          },
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "501": {"$ref": "#/components/responses/NotImplemented"}
        },
        "security": [{"oauth2_client_credentials": ["book:api"]}]
      }
    },
    "/book/api/order": {
      "get": {
        "tags": ["booking"],
        "summary": "Look up an order by reference + email",
        "operationId": "getOrder",
        "parameters": [
          {"name": "ref", "in": "query", "required": true, "schema": {"type": "integer"}, "description": "Order id (`idorder`)"},
          {"name": "email", "in": "query", "required": true, "schema": {"type": "string", "format": "email"}, "description": "Customer email; must match the email on the order."}
        ],
        "responses": {
          "200": {
            "description": "Order details",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Order"}
              }
            }
          },
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "404": {"$ref": "#/components/responses/Error"},
          "501": {"$ref": "#/components/responses/NotImplemented"}
        },
        "security": [{"oauth2_client_credentials": ["book:api"]}]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "oauth2_client_credentials": {
        "type": "oauth2",
        "description": "OAuth 2.0 client_credentials grant. Register a client at /oauth/register, exchange credentials at /oauth/token, then send the bearer token. Discovery: /.well-known/oauth-authorization-server.",
        "flows": {
          "clientCredentials": {
            "tokenUrl": "/oauth/token",
            "scopes": {
              "book:api": "Access protected booking-flow endpoints (cart, customer, booking, payment, order)"
            }
          }
        }
      }
    },
    "schemas": {
      "Location": {
        "type": "object",
        "properties": {
          "id": {"type": "string", "description": "Location id; sublocations are encoded as `parent_child`."},
          "name": {"type": "string"},
          "type": {"type": "string"},
          "parent_id": {"type": ["string", "null"]},
          "lat": {"type": ["number", "null"]},
          "lng": {"type": ["number", "null"]}
        },
        "required": ["id", "name"]
      },
      "Availability": {
        "type": "object",
        "properties": {
          "idavailability": {"type": "integer"},
          "idcompany": {"type": "integer"},
          "company_name": {"type": "string"},
          "idboatroute": {"type": "integer"},
          "from": {
            "type": "string",
            "description": "Departure location id (matches `id` from `/book/api/locations`)."
          },
          "to": {
            "type": "string",
            "description": "Arrival location id (matches `id` from `/book/api/locations`)."
          },
          "idlocation_departure": {
            "type": [
              "integer",
              "string"
            ],
            "description": "Deprecated; prefer `from`."
          },
          "idlocation_arrival": {
            "type": [
              "integer",
              "string"
            ],
            "description": "Deprecated; prefer `to`."
          },
          "departure": {"type": "string", "format": "date-time"},
          "arrival": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Scheduled arrival time when available."
          },
          "price": {
            "type": "number",
            "description": "Total price for all passengers in the search, in the listed currency."
          },
          "price_per_person": {
            "type": [
              "number",
              "null"
            ],
            "description": "`price` divided by the paying-passenger count (adults + children + seniors)."
          },
          "currency": {"type": "string"}
        },
        "required": ["idavailability", "departure", "price"]
      },
      "Customer": {
        "type": "object",
        "properties": {
          "first_name": {"type": "string"},
          "last_name": {"type": "string"},
          "email": {"type": "string", "format": "email"},
          "phone": {"type": "string"},
          "address": {"type": "string"},
          "country": {"type": "string"}
        },
        "required": ["first_name", "last_name", "email"]
      },
      "Cart": {
        "type": "object",
        "properties": {
          "items": {"type": "array", "items": {"type": "object"}},
          "customer": {"$ref": "#/components/schemas/Customer"},
          "currency": {"type": "string"},
          "total": {"type": "number"}
        }
      },
      "Order": {
        "type": "object",
        "properties": {
          "idorder": {"type": "integer"},
          "status": {"type": "string", "enum": ["open", "paid", "cancelled"]},
          "currency": {"type": "string"},
          "total": {"type": "number"},
          "created_on": {"type": "string", "format": "date-time"},
          "items": {"type": "array", "items": {"type": "object"}}
        }
      },
      "ApiError": {
        "type": "object",
        "properties": {
          "error": {"type": "string", "description": "Machine-readable error code."},
          "message": {"type": "string", "description": "Human-readable explanation."}
        },
        "required": ["error", "message"]
      }
    },
    "responses": {
      "Cart": {
        "description": "Current cart contents",
        "content": {
          "application/json": {
            "schema": {"$ref": "#/components/schemas/Cart"}
          }
        }
      },
      "Error": {
        "description": "Error",
        "content": {
          "application/json": {
            "schema": {"$ref": "#/components/schemas/ApiError"}
          }
        }
      },
      "NotImplemented": {
        "description": "Endpoint reserved but not yet implemented.",
        "content": {
          "application/json": {
            "schema": {"$ref": "#/components/schemas/ApiError"}
          }
        }
      },
      "Unauthorized": {
        "description": "Missing, invalid, or expired bearer token; or the token lacks the required scope.",
        "headers": {
          "WWW-Authenticate": {
            "schema": {"type": "string"},
            "description": "Bearer challenge per RFC 6750"
          }
        },
        "content": {
          "application/json": {
            "schema": {"$ref": "#/components/schemas/ApiError"}
          }
        }
      }
    }
  }
}
