{
 "openapi": "3.1.0",
 "info": {
  "title": "Southern Roof Surveys booking API",
  "version": "1.0.0",
  "summary": "Price, check availability and book an independent roof survey in the south of England.",
  "description": "Open API, no key needed. Flow: GET /api/catalog, GET /api/quote, GET /api/availability, POST /api/book. Nothing is charged by this API: the customer is emailed a secure card payment link and the booking is confirmed when it is paid. Confirm report, price, date and time with the customer before booking. The service is an independent roof condition report by roof surveyors; it is not an RICS or structural survey. Human guide: https://southernroofsurveys.co.uk/book-with-ai/",
  "contact": {
   "name": "Southern Roof Surveys",
   "url": "https://southernroofsurveys.co.uk/",
   "email": "info@southernroofsurveys.co.uk"
  }
 },
 "servers": [
  {
   "url": "https://southernroofsurveys.co.uk"
  }
 ],
 "paths": {
  "/api/catalog": {
   "get": {
    "operationId": "listReports",
    "summary": "List reports, add-ons, prices and travel zones",
    "responses": {
     "200": {
      "description": "Catalogue",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Catalog"
        }
       }
      }
     }
    }
   }
  },
  "/api/quote": {
   "get": {
    "operationId": "getQuote",
    "summary": "Fixed price for one report at a UK postcode, including travel",
    "parameters": [
     {
      "name": "postcode",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "description": "Full UK postcode of the property",
       "examples": [
        "GU51 4AB"
       ]
      }
     },
     {
      "name": "product",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "description": "Report id",
       "enum": [
        "drone-roof-report",
        "full-roof-condition-report",
        "pre-purchase-roof-report"
       ]
      }
     },
     {
      "name": "addons",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "description": "Comma-separated add-on ids: thermal, second-building, express-24h"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Quote",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Quote"
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "Property is outside the service area",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/api/availability": {
   "get": {
    "operationId": "checkAvailability",
    "summary": "Free inspection dates and arrival times (Europe/London)",
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "description": "Start date YYYY-MM-DD",
       "format": "date"
      }
     },
     {
      "name": "days",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 28,
       "default": 14
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Availability",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Availability"
        }
       }
      }
     },
     "503": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/api/book": {
   "post": {
    "operationId": "bookSurvey",
    "summary": "Hold a slot and create a booking. No payment is taken.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/BookingRequest"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Booking created, slot held",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Booking"
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "Slot no longer available; alternatives returned",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/api/booking": {
   "get": {
    "operationId": "getBooking",
    "summary": "Look up a booking",
    "parameters": [
     {
      "name": "ref",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "description": "Booking reference"
      }
     },
     {
      "name": "token",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "description": "Token returned when the booking was made"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Booking",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Booking"
        }
       }
      }
     },
     "403": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "cancelBooking",
    "summary": "Cancel an unpaid booking and free the slot",
    "parameters": [
     {
      "name": "ref",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "description": "Booking reference"
      }
     },
     {
      "name": "token",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "description": "Token returned when the booking was made"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Cancelled booking",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Booking"
        }
       }
      }
     },
     "403": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "schemas": {
   "Error": {
    "type": "object",
    "properties": {
     "ok": {
      "type": "boolean",
      "const": false
     },
     "error": {
      "type": "string",
      "description": "Machine-readable code, e.g. bad_postcode, out_of_area, slot_taken, invalid"
     },
     "message": {
      "type": "string",
      "description": "Explanation suitable to show the customer"
     }
    }
   },
   "Catalog": {
    "type": "object",
    "properties": {
     "products": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string",
         "description": "Report id"
        },
        "name": {
         "type": "string",
         "description": "Name"
        },
        "priceGBP": {
         "type": "number"
        },
        "url": {
         "type": "string",
         "description": "Page describing the report"
        },
        "summary": {
         "type": "string",
         "description": "What it covers"
        }
       }
      }
     },
     "addons": {
      "type": "array",
      "items": {
       "type": "object"
      }
     },
     "zones": {
      "type": "array",
      "items": {
       "type": "object"
      }
     }
    }
   },
   "Quote": {
    "type": "object",
    "properties": {
     "product": {
      "type": "string",
      "description": "Report id"
     },
     "postcode": {
      "type": "string",
      "description": "Normalised postcode"
     },
     "zone": {
      "type": [
       "integer",
       "null"
      ]
     },
     "estimatedRoadMiles": {
      "type": [
       "integer",
       "null"
      ]
     },
     "lines": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "label": {
         "type": "string",
         "description": "Line"
        },
        "gbp": {
         "type": "number"
        }
       }
      }
     },
     "totalGBP": {
      "type": "number"
     },
     "priceFinal": {
      "type": "boolean"
     },
     "reportTurnaroundHours": {
      "type": "integer"
     },
     "note": {
      "type": [
       "string",
       "null"
      ]
     }
    }
   },
   "Availability": {
    "type": "object",
    "properties": {
     "timezone": {
      "type": "string",
      "description": "Always Europe/London"
     },
     "earliestDate": {
      "type": "string",
      "description": "First bookable date",
      "format": "date"
     },
     "days": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "date": {
         "type": "string",
         "description": "YYYY-MM-DD",
         "format": "date"
        },
        "label": {
         "type": "string",
         "description": "Readable date"
        },
        "times": {
         "type": "array",
         "items": {
          "type": "string",
          "description": "HH:MM arrival time"
         }
        }
       }
      }
     }
    }
   },
   "BookingRequest": {
    "type": "object",
    "required": [
     "product",
     "postcode",
     "address",
     "date",
     "time",
     "name",
     "phone",
     "email"
    ],
    "properties": {
     "product": {
      "type": "string",
      "description": "Report id",
      "enum": [
       "drone-roof-report",
       "full-roof-condition-report",
       "pre-purchase-roof-report"
      ]
     },
     "addons": {
      "type": "array",
      "items": {
       "type": "string",
       "description": "Add-on id",
       "enum": [
        "thermal",
        "second-building",
        "express-24h"
       ]
      }
     },
     "postcode": {
      "type": "string",
      "description": "Postcode of the property to survey"
     },
     "address": {
      "type": "string",
      "description": "House number, street and town of the property"
     },
     "date": {
      "type": "string",
      "description": "Slot date from /api/availability",
      "format": "date"
     },
     "time": {
      "type": "string",
      "description": "Slot time HH:MM from /api/availability"
     },
     "name": {
      "type": "string",
      "description": "Customer full name"
     },
     "phone": {
      "type": "string",
      "description": "Customer phone number"
     },
     "email": {
      "type": "string",
      "description": "Customer email; report and payment link are sent here",
      "format": "email"
     },
     "property_type": {
      "type": "string",
      "description": "e.g. Detached house, Terraced house, Bungalow, Flat"
     },
     "purpose": {
      "type": "string",
      "description": "Why the report is needed"
     },
     "report_for": {
      "type": "string",
      "description": "Lender, solicitor or insurer to name on the report"
     },
     "access": {
      "type": "string",
      "description": "Who gives access on the day, if not the customer"
     },
     "notes": {
      "type": "string",
      "description": "Anything else, e.g. the valuer's wording"
     }
    }
   },
   "Booking": {
    "type": "object",
    "properties": {
     "ok": {
      "type": "boolean"
     },
     "ref": {
      "type": "string",
      "description": "Booking reference"
     },
     "status": {
      "type": "string",
      "description": "Booking state",
      "enum": [
       "held",
       "paid",
       "cancelled",
       "requested"
      ]
     },
     "product": {
      "type": "string",
      "description": "Report name"
     },
     "date": {
      "type": "string",
      "description": "Date",
      "format": "date"
     },
     "time": {
      "type": "string",
      "description": "Arrival time"
     },
     "dateLabel": {
      "type": "string",
      "description": "Readable date"
     },
     "postcode": {
      "type": "string",
      "description": "Postcode"
     },
     "totalGBP": {
      "type": "number"
     },
     "paymentUrl": {
      "type": [
       "string",
       "null"
      ],
      "description": "Secure card payment page for the customer, when available"
     },
     "token": {
      "type": "string",
      "description": "Private token needed to look up or cancel; returned once"
     },
     "note": {
      "type": "string",
      "description": "What happens next"
     }
    }
   }
  }
 }
}