openapi: 3.0.3
info:
  title: Direct Bookings Italy API
  description: |
    Book accommodation in Italy directly with local hosts. No commissions.
    Covers 20+ cities including Rome, Florence, Milan, Naples, Venice, Amalfi, and more.
    Flow: search -> poll status -> accept quote.
  version: "1.0.0"
  contact:
    email: info@directbookingsitaly.com
    url: https://www.directbookingsitaly.com
servers:
  - url: https://www.directbookingsitaly.com/api/public

paths:
  /search:
    post:
      operationId: searchAccommodation
      summary: Search for accommodation in an Italian city
      description: |
        Creates a booking request and notifies local hosts.
        Returns rfq_id and guest_token needed for status checks and accepting quotes.
        Hosts typically respond within 1-24 hours.
        City names work in English or Italian (e.g. "Rome" or "Roma").
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [city, check_in, check_out, guest_name, guest_email]
              properties:
                city:
                  type: string
                  description: Italian city (English or Italian name)
                  example: Rome
                check_in:
                  type: string
                  format: date
                  description: Arrival date YYYY-MM-DD
                  example: "2026-07-12"
                check_out:
                  type: string
                  format: date
                  description: Departure date YYYY-MM-DD
                  example: "2026-07-18"
                guest_name:
                  type: string
                  description: Guest's full name
                  example: John Smith
                guest_email:
                  type: string
                  format: email
                  description: Guest's email for host communication
                  example: john@example.com
                adults:
                  type: integer
                  minimum: 1
                  maximum: 20
                  default: 2
                  description: Number of adults
                children:
                  type: integer
                  minimum: 0
                  maximum: 10
                  default: 0
                  description: Number of children
                budget_max:
                  type: number
                  minimum: 10
                  maximum: 10000
                  default: 200
                  description: Maximum budget in EUR per night
                neighborhood:
                  type: string
                  description: Preferred area (e.g. "Trastevere", "Centro Storico")
                amenities:
                  type: array
                  items:
                    type: string
                  description: Desired amenities (wifi, pool, parking, ac, etc)
                special_requests:
                  type: string
                  description: Any special requirements
      responses:
        "201":
          description: Search created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                  rfq_id:
                    type: string
                    format: uuid
                    description: Booking request ID (save this)
                  guest_token:
                    type: string
                    description: Auth token for this request (save this)
                  hosts_notified:
                    type: integer
                    description: Number of hosts contacted
                  poll_url:
                    type: string
                    description: URL to check for quotes
                  message:
                    type: string
        "400":
          description: Validation error
        "429":
          description: Rate limited (max 10/hour)

  /status:
    get:
      operationId: checkStatus
      summary: Check booking status and get quotes
      description: |
        Poll this endpoint to check if hosts have sent quotes.
        Requires rfq_id and guest_token from the search response.
        Returns the RFQ details and any available quotes with prices.
      parameters:
        - name: rfq_id
          in: query
          required: true
          schema:
            type: string
            format: uuid
          description: Booking request ID from search
        - name: guest_token
          in: query
          required: true
          schema:
            type: string
          description: Auth token from search
      responses:
        "200":
          description: Status and quotes
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                  rfq:
                    type: object
                    properties:
                      id:
                        type: string
                      city:
                        type: string
                      neighborhood:
                        type: string
                      check_in:
                        type: string
                      check_out:
                        type: string
                      adults:
                        type: integer
                      children:
                        type: integer
                      budget_max:
                        type: number
                      status:
                        type: string
                        enum: [active, matching, matched, expired, cancelled]
                  quotes:
                    type: array
                    items:
                      type: object
                      properties:
                        quote_id:
                          type: string
                          format: uuid
                        price_per_night:
                          type: number
                        total_price:
                          type: number
                        currency:
                          type: string
                          default: EUR
                        cleaning_fee:
                          type: number
                        host_message:
                          type: string
                        valid_until:
                          type: string
                          format: date-time
                        status:
                          type: string
                        cancellation_policy:
                          type: string
                  message:
                    type: string
        "404":
          description: RFQ not found or invalid token

  /accept:
    post:
      operationId: acceptQuote
      summary: Accept a host's quote
      description: |
        Confirms a booking at the quoted price. The host will be notified
        and will reach out with final details. Other pending quotes for the
        same request are automatically declined.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [quote_id, guest_token]
              properties:
                quote_id:
                  type: string
                  format: uuid
                  description: The quote to accept (from status response)
                guest_token:
                  type: string
                  description: Auth token from search
      responses:
        "200":
          description: Quote accepted
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                  quote:
                    type: object
                    properties:
                      quote_id:
                        type: string
                      price_per_night:
                        type: number
                      total_price:
                        type: number
                      currency:
                        type: string
                      cleaning_fee:
                        type: number
                      host_message:
                        type: string
                      status:
                        type: string
                  message:
                    type: string
        "400":
          description: Quote expired or already processed
        "403":
          description: Invalid guest token
        "404":
          description: Quote not found
