openapi: 3.1.0
info:
  title: Padel Desk Booking Source API
  version: 0.2.1
  contact:
    name: More Padel
    email: info@morepadel.co
    url: https://padeldeskapp.com
  description: |
    Padel Desk is a venue's front desk system: reservation board, checks, payments and
    end-of-day reconciliation. A booking source is a platform where players or venue staff
    reserve the venue's courts. A booking source implements this API so that the venue's
    bookings reach its front desk, and front desk bookings reach the booking source.

    Names and shapes are a proposal; the data and operations are the requirement. This
    document is open to comment. A booking source may add fields and enum values at any time; any
    other change needs a new version.

    ## Conventions

    - **Scope:** one credential per venue, authorised by the venue. It reads, and receives
      events for, every booking and block at that venue, whoever created it.
    - **Write scope:** the venue is the authority over its courts. Padel Desk may move,
      extend or cancel any booking of the venue and remove any block of the venue, whoever
      created it. It sets the venue's setup: profile, opening hours, courts, booking rules
      and prices. It does not change a booking's customer, players, price or payment. An
      unknown id in a path returns 404. An unknown or inactive court in the body of a
      booking or block request returns 422.
    - **Time:** RFC 3339 timestamps in UTC, written with `Z` and millisecond precision.
      Intervals are start-inclusive, end-exclusive. A queried range is at most 31 days.
    - **Money:** integer minor units with an ISO 4217 currency. No floating point.
    - **Identifiers:** opaque strings, stable for the life of the record.
    - **Idempotency:** creates carry a `reference` chosen by Padel Desk, unique per venue.
      Bookings and blocks have separate references. The booking source compares a repeated
      create with the first create request of that reference, not with the record as it is
      now. The same court, start and end returns the record that request created, in its
      current state, even after a move or a cancel, and never creates another. A different
      court, start or end returns 409 `reference_reused`. A taken interval returns 409
      `interval_taken`.
    - **Pagination:** `limit` and `cursor`; responses return `nextCursor`, null when finished.
    - **Errors:** every non-2xx response is an `Error` object.
    - **Rate limits:** per credential, never per source IP; Padel Desk venues share outbound
      IP addresses. 429 carries `Retry-After` in seconds.
    - **Venue authority:** a venue credential may book after the end of the players' booking
      window, and may book an interval that crosses local midnight. Every booking that
      Padel Desk creates, moves or extends is one slot of the court: it starts on a start
      step, its length is one of the court's `durations`, and it ends at or before the
      close. Any other interval returns 422.

    ## Connection

    The booking source gives the venue two values: the base URL of this API and the venue's
    token. The venue enters them in Padel Desk. No one signs in to the booking source to
    finish the connection, and no setting is typed in there. Padel Desk then:

    1. Reads `GET /venue` to confirm the token and the venue.
    2. Sends its webhook URL and a signing secret with `PUT /webhook`.
    3. Reads `GET /courts`. The venue matches each court that already exists to a court in
       Padel Desk, once, in Padel Desk.
    4. Sends the venue's setup with `PUT /setup`.
    5. Reads the slots the booking source builds from the setup with `GET /slots` and
       compares them with its own.
    6. Reads the bookings and blocks, and follows changes through events.

    ## Setup

    Padel Desk is the single source of the venue's setup. The setup is one document: the
    venue's profile, opening hours, courts with their booking rules, and prices. The booking
    source applies the whole document or none of it, and shows its players what the document
    says. While a venue is connected, the booking source does not change these values on its
    own side. When the venue changes one in Padel Desk, Padel Desk sends the whole document
    again with a higher `version`.

    The connection works only while the slots agree. If the slots of the booking source
    differ from those of Padel Desk, Padel Desk shows the venue the difference and exchanges
    no bookings until they agree. Because the slots agree, a booking that Padel Desk creates
    always fits them.

    The booking source keeps its own rules for players: how far ahead they book, and its
    cancellation and refund policy.

    Disconnecting in Padel Desk calls `DELETE /webhook`. The booking source then sends no
    more events. The applied setup stays as it is, and the venue may change it at the
    booking source again. Bookings and blocks that Padel Desk created stay. When the venue
    connects again, Padel Desk repeats the steps above. It raises `version` on every
    connection, so the booking source applies the setup again and replaces any value the
    venue changed there meanwhile.

    The event feed of `GET /events` does not depend on the webhook: the booking source
    records events also while no webhook is set.

    ## Booking states

    - `PENDING`: awaiting confirmation at the booking source, for example a payment in
      progress. It occupies the court. It becomes `CONFIRMED` or `CANCELLED`.
    - `CONFIRMED`: the court is reserved. It can become `CANCELLED`.
    - `CANCELLED`: final. It no longer occupies the court and cannot be moved; a move
      returns 409.

    A booking created through this API is `CONFIRMED` at once. Cancelling a cancelled booking
    and removing a removed block both succeed.

    ## Privacy

    Padel Desk sends no customer name, phone or email to a booking source. A booking created
    by Padel Desk is an occupied interval identified by its opaque `reference` only: it has no
    customer, players or price at the booking source and needs no player-facing behaviour.
    Padel Desk creates regular and lesson bookings only; open matches and tournaments start
    at the booking source.

    The venue needs the customer and players of its bookings to run its front desk: to
    receive them, open their check and reach them. Padel Desk holds that data on the venue's
    behalf and never passes it to another booking source.

    ## Environments

    A sandbox with a test venue, courts and credentials is required before go-live.
servers:
  - url: https://BOOKING_SOURCE_API_BASE_URL
security:
  - venueToken: []

paths:
  /venue:
    get:
      operationId: getVenue
      summary: Venue of the authenticated credential
      responses:
        '200':
          description: Venue
          content:
            application/json:
              schema:
                type: object
                required: [id, name, timezone, currency]
                properties:
                  id: { type: string }
                  name: { type: string }
                  timezone: { type: string, description: IANA timezone., examples: [Europe/Istanbul] }
                  currency: { type: string, description: ISO 4217 currency of the venue's prices., examples: [TRY] }
        default: { $ref: '#/components/responses/Error' }

  /setup:
    get:
      operationId: getSetup
      summary: Setup the booking source has applied
      description: Padel Desk reads it to confirm what is applied. 404 before the first `PUT /setup`.
      responses:
        '200':
          description: Applied setup, with the booking source's id on every court
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Setup' }
        '404': { description: No setup has been applied yet., content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
        default: { $ref: '#/components/responses/Error' }
    put:
      operationId: setSetup
      summary: Set the venue's setup
      description: |
        Replaces the whole setup. The booking source applies all of it or none of it.

        A court with a `courtId` updates that existing court. A court without one is created,
        unless a court with the same `reference` exists. A `courtId` that the booking source
        does not know, or a `reference` that already belongs to another court, returns 422.
        A court of the venue that is absent from the document becomes inactive; it is never
        deleted. `GET /setup` returns the document as applied, so it leaves that court out;
        `GET /courts` still lists it, with `active` false. Bookings that exist outside
        the new opening hours, or on a court that becomes inactive, stay as they are. A
        closure on one date is a block, not a change of setup. Prices apply to bookings made
        after the call; the price of an existing booking does not change.

        `version` is compared with the applied setup only. The booking source compares
        content with the request body it last applied, as Padel Desk sent it. The same
        `version` with the same content succeeds again. The same `version` with different content, or a lower
        `version`, returns 409 `conflict`. A setup that was refused was never applied, so
        Padel Desk may send its `version` again with corrected content.

        A booking source that cannot apply a value returns 422 `unprocessable`, names the
        field in `message` and applies nothing. Examples are a court with more than one
        booking length, a close after midnight, or price rules that overlap.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Setup' }
      responses:
        '200':
          description: Applied setup, with the booking source's id on every court
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Setup' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422':
          description: '`unprocessable`: the booking source cannot apply a value; `message` names the field. Nothing is applied.'
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Error' }
        default: { $ref: '#/components/responses/Error' }

  /courts:
    get:
      operationId: listCourts
      summary: Courts of the venue at the booking source
      parameters:
        - { $ref: '#/components/parameters/Limit' }
        - { $ref: '#/components/parameters/Cursor' }
      responses:
        '200':
          description: Page of courts
          content:
            application/json:
              schema:
                type: object
                required: [items, nextCursor]
                properties:
                  items: { type: array, items: { $ref: '#/components/schemas/Court' } }
                  nextCursor: { type: [string, 'null'] }
        default: { $ref: '#/components/responses/Error' }

  /webhook:
    put:
      operationId: setWebhook
      summary: Set where the venue's events are sent
      description: |
        Replaces any earlier URL and secret for this venue. From this call on, the booking
        source sends events to `url` and signs them with `secret`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [url, secret]
              properties:
                url: { type: string, format: uri, description: HTTPS URL of Padel Desk for this venue. }
                secret: { type: string, minLength: 32, description: Signing secret chosen by Padel Desk. Never returned by any endpoint. }
      responses:
        '204': { description: Stored }
        default: { $ref: '#/components/responses/Error' }
    delete:
      operationId: removeWebhook
      summary: Stop sending the venue's events
      responses:
        '204': { description: Removed }
        default: { $ref: '#/components/responses/Error' }

  /slots:
    get:
      operationId: listSlots
      summary: Slots of one venue day
      description: |
        Every slot of each active court on the venue day that opens on `date`, taken or not.
        Slots come from the setup only: the opening hours, and each court's `durations` and
        `startStep`. A slot starts on a start step and ends at or before the close. Prices,
        the players' booking window, the current time, bookings and blocks do not add or
        remove slots. A court that accepts more than one booking length returns a slot for
        each start and length.

        Padel Desk compares these with its own slots, and the connection works only while
        they agree. Padel Desk may book any slot, also one that no price rule covers. `GET
        /availability` tells which are busy.
      parameters:
        - name: date
          in: query
          required: true
          description: Venue-local date.
          schema: { type: string, format: date, examples: ['2026-10-13'] }
        - { $ref: '#/components/parameters/CourtId' }
      responses:
        '200':
          description: Slots
          content:
            application/json:
              schema:
                type: object
                required: [items]
                properties:
                  items:
                    type: array
                    items:
                      type: object
                      required: [courtId, start, end]
                      properties:
                        courtId: { type: string }
                        start: { type: string, format: date-time }
                        end: { type: string, format: date-time }
        default: { $ref: '#/components/responses/Error' }

  /availability:
    get:
      operationId: readAvailability
      summary: Busy intervals
      description: |
        Everything that prevents a booking in the range: bookings, blocks and temporary
        holds. An interval absent here is only a candidate; create performs the final check.
      parameters:
        - { $ref: '#/components/parameters/From' }
        - { $ref: '#/components/parameters/To' }
        - { $ref: '#/components/parameters/CourtId' }
      responses:
        '200':
          description: Busy intervals
          content:
            application/json:
              schema:
                type: object
                required: [items]
                properties:
                  items:
                    type: array
                    items:
                      type: object
                      required: [courtId, start, end]
                      properties:
                        courtId: { type: string }
                        start: { type: string, format: date-time }
                        end: { type: string, format: date-time }
        default: { $ref: '#/components/responses/Error' }

  /bookings:
    get:
      operationId: listBookings
      summary: All bookings of the venue
      description: |
        Includes bookings made by players, past bookings and cancelled bookings. Supply a
        range (`from` and `to`) or a `reference`; a request with neither returns 400. A range
        returns bookings that overlap it.
        Used for the first import and for reconciliation; changes arrive as events.
      parameters:
        - { name: from, in: query, schema: { type: string, format: date-time } }
        - { name: to, in: query, description: Exclusive., schema: { type: string, format: date-time } }
        - { $ref: '#/components/parameters/CourtId' }
        - name: reference
          in: query
          description: Exact match; recovers a booking whose create response was lost.
          schema: { type: string }
        - { $ref: '#/components/parameters/Limit' }
        - { $ref: '#/components/parameters/Cursor' }
      responses:
        '200':
          description: Page of bookings
          content:
            application/json:
              schema:
                type: object
                required: [items, nextCursor]
                properties:
                  items: { type: array, items: { $ref: '#/components/schemas/Booking' } }
                  nextCursor: { type: [string, 'null'] }
        default: { $ref: '#/components/responses/Error' }
    post:
      operationId: createBooking
      summary: Create a confirmed booking
      description: |
        The booking is an occupied interval with no customer, players or price at the booking
        source. The interval must be one slot of the court; any other returns 422.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [reference, courtId, start, end]
              properties:
                reference: { type: string, maxLength: 191, description: Opaque idempotency reference. }
                courtId: { type: string }
                start: { type: string, format: date-time }
                end: { type: string, format: date-time }
                type:
                  type: string
                  enum: [REGULAR, LESSON]
                  default: REGULAR
                note:
                  type: [string, 'null']
                  maxLength: 500
                  description: Sent only when the venue has opted in to sharing notes.
      responses:
        '201':
          description: Booking, or the existing booking for an identical retry
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Booking' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Unprocessable' }
        default: { $ref: '#/components/responses/Error' }

  /bookings/{bookingId}:
    parameters:
      - { name: bookingId, in: path, required: true, schema: { type: string } }
    get:
      operationId: getBooking
      summary: One booking of the venue
      responses:
        '200':
          description: Booking
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Booking' }
        '404': { $ref: '#/components/responses/NotFound' }
        default: { $ref: '#/components/responses/Error' }
    patch:
      operationId: updateBooking
      summary: Move or extend any booking of the venue
      description: |
        Keeps the booking's id. Omitted fields are unchanged. The booking's own current
        interval does not conflict with its new one. A conflict returns 409 and changes
        nothing. The new interval must be one slot of the booking's court after the change;
        any other returns 422. For a booking made by a player, the booking source applies its
        own price and refund rules and tells the players.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              minProperties: 1
              properties:
                courtId: { type: string }
                start: { type: string, format: date-time }
                end: { type: string, format: date-time }
      responses:
        '200':
          description: Updated booking
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Booking' }
        '409': { $ref: '#/components/responses/Conflict' }
        '404': { $ref: '#/components/responses/NotFound' }
        '422': { $ref: '#/components/responses/Unprocessable' }
        default: { $ref: '#/components/responses/Error' }

  /bookings/{bookingId}/cancel:
    post:
      operationId: cancelBooking
      summary: Cancel any booking of the venue
      description: |
        The venue may cancel a booking made by a player, for example when rain closes the
        court. The booking source applies its own refund rules and tells the players. The
        booking's `cancelledBy` becomes `PADEL_DESK`. Cancelling an already cancelled booking
        succeeds and changes nothing.
      parameters:
        - { name: bookingId, in: path, required: true, schema: { type: string } }
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                reason:
                  type: [string, 'null']
                  maxLength: 200
                  description: Short reason from the venue, which the booking source may show to the players.
      responses:
        '200':
          description: Cancelled booking
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Booking' }
        '404': { $ref: '#/components/responses/NotFound' }
        default: { $ref: '#/components/responses/Error' }

  /blocks:
    get:
      operationId: listBlocks
      summary: Court blocks that overlap a range
      description: Maintenance and closures, whoever created them. Not customer reservations. Removed blocks are not listed.
      parameters:
        - { $ref: '#/components/parameters/From' }
        - { $ref: '#/components/parameters/To' }
        - { $ref: '#/components/parameters/CourtId' }
        - { $ref: '#/components/parameters/Limit' }
        - { $ref: '#/components/parameters/Cursor' }
      responses:
        '200':
          description: Page of blocks
          content:
            application/json:
              schema:
                type: object
                required: [items, nextCursor]
                properties:
                  items: { type: array, items: { $ref: '#/components/schemas/Block' } }
                  nextCursor: { type: [string, 'null'] }
        default: { $ref: '#/components/responses/Error' }
    post:
      operationId: createBlock
      summary: Close a court for an interval
      description: |
        For rain, repair or a private closure. Any interval length; a block need not be a
        slot. Does not cancel existing bookings; an overlap with a booking returns 409.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [reference, courtId, start, end]
              properties:
                reference: { type: string, maxLength: 191, description: Opaque idempotency reference. }
                courtId: { type: string }
                start: { type: string, format: date-time }
                end: { type: string, format: date-time }
                reason: { type: [string, 'null'], maxLength: 500 }
      responses:
        '201':
          description: Block, or the existing block for an identical retry
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Block' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { description: '`unprocessable`: the court is unknown or inactive.', content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
        default: { $ref: '#/components/responses/Error' }

  /blocks/{blockId}:
    delete:
      operationId: removeBlock
      summary: Remove any block of the venue
      parameters:
        - { name: blockId, in: path, required: true, schema: { type: string } }
      responses:
        '204': { description: Removed }
        '404': { $ref: '#/components/responses/NotFound' }
        default: { $ref: '#/components/responses/Error' }

  /events:
    get:
      operationId: listEvents
      summary: Change feed of the venue
      description: |
        Every event for this venue in `sequence` order, delivered by webhook or not, kept at
        least 7 days. Padel Desk keeps its own place in this feed and reads it on a schedule
        and after downtime, so an event that no webhook delivered is still found. Sequences
        only need to increase; they need not be consecutive.

        Every response carries `latestSequence`, the sequence of the venue's newest event, or
        0 when the venue has none. When connecting, Padel Desk calls this with `after=0` to
        learn `latestSequence`; the answer is 200, or 410 when older events are already
        deleted, and both carry it. Padel Desk then reads bookings and blocks by range and
        follows the feed from that sequence.

        410 `expired` is returned only when the booking source has deleted an event whose
        sequence is greater than `after`. Padel Desk then reads bookings and blocks by range
        again and continues from the `latestSequence` in that response.
      parameters:
        - name: after
          in: query
          required: true
          description: Return events whose sequence is greater than this.
          schema: { type: integer, format: int64 }
        - { $ref: '#/components/parameters/Limit' }
      responses:
        '200':
          description: Events in sequence order; an empty list when there are none after `after`.
          content:
            application/json:
              schema:
                type: object
                required: [items, latestSequence]
                properties:
                  items: { type: array, items: { $ref: '#/components/schemas/Event' } }
                  latestSequence: { type: integer, format: int64, description: Sequence of the venue's newest event; 0 when there is none. }
        '410':
          description: '`expired`: an event after `after` is no longer kept.'
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Error'
                  - type: object
                    required: [latestSequence]
                    properties:
                      latestSequence: { type: integer, format: int64 }
        default: { $ref: '#/components/responses/Error' }

webhooks:
  event:
    post:
      operationId: receiveEvent
      summary: Booking source to Padel Desk event delivery
      description: |
        Sent to the URL set with `PUT /webhook`, for every booking and block
        of that venue. `booking.updated` is sent when any field of the booking changes,
        including players, price and payment. `block.updated` is sent when venue staff change
        a block in the booking source's own tools.

        Any 2xx response accepts the event. Padel Desk refuses an event whose
        `X-Event-Timestamp` differs from its clock by more than 5 minutes.

        Delivery is retried on 429 and 5xx for at least 24 hours. Delivery order is not
        guaranteed; Padel Desk deduplicates by `id` and applies events by `sequence`.
      security: []
      parameters:
        - name: X-Event-Timestamp
          in: header
          required: true
          description: Send time, RFC 3339 UTC. Part of the signed content.
          schema: { type: string, format: date-time }
        - name: X-Event-Signature
          in: header
          required: true
          description: |
            `v1={hex HMAC-SHA256}` over `{X-Event-Timestamp}.{raw body}`, using the secret
            from the latest `PUT /webhook` of this venue.
          schema: { type: string }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Event' }
      responses:
        '204': { description: Event stored by Padel Desk }

components:
  securitySchemes:
    venueToken:
      type: http
      scheme: bearer
      description: Secret token issued per venue.

  parameters:
    From: { name: from, in: query, required: true, schema: { type: string, format: date-time } }
    To: { name: to, in: query, required: true, description: Exclusive., schema: { type: string, format: date-time } }
    CourtId: { name: courtId, in: query, schema: { type: string } }
    Limit: { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 50 } }
    Cursor: { name: cursor, in: query, schema: { type: string } }

  responses:
    Error:
      description: Error
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    NotFound:
      description: '`not_found`: the venue has no record with this id.'
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    Unprocessable:
      description: '`unprocessable`: the interval is not a slot of the court, or the court is unknown or inactive.'
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    Conflict:
      description: |
        `interval_taken`: another booking, block or hold uses the interval.
        `reference_reused`: the reference belongs to a record with a different court, start or end.
        `conflict`: the record's state does not allow the change.
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }

  schemas:
    Error:
      type: object
      required: [error, message]
      properties:
        error:
          type: string
          description: Stable machine-readable code.
          enum: [bad_request, unauthorized, forbidden, not_found, interval_taken, reference_reused, conflict, expired, unprocessable, rate_limited, unavailable]
        message: { type: string, description: Human-readable explanation. }

    BookingType:
      type: string
      enum: [REGULAR, OPEN_MATCH, LESSON, TOURNAMENT]

    Booking:
      type: object
      required: [id, courtId, start, end, status, type, origin, reference, note, customer, players, price, payment, cancelledAt, cancelledBy, createdAt, updatedAt]
      properties:
        id: { type: string }
        courtId: { type: string }
        start: { type: string, format: date-time }
        end: { type: string, format: date-time }
        status: { type: string, enum: [PENDING, CONFIRMED, CANCELLED] }
        type: { $ref: '#/components/schemas/BookingType' }
        origin:
          type: string
          enum: [PLAYER, VENUE, PADEL_DESK]
          description: |
            PLAYER: booked by a player in the booking source's app. VENUE: booked by venue
            staff in the booking source's own tools. PADEL_DESK: created through this API.
        reference: { type: [string, 'null'], description: Set only for bookings created through this API. }
        note: { type: [string, 'null'] }
        customer:
          description: |
            The customer the booking belongs to; for an open match, the player who opened it.
            Null for bookings created through this API.
          oneOf: [{ $ref: '#/components/schemas/Person' }, { type: 'null' }]
        players:
          type: array
          description: Everyone on the booking, including the customer when they play.
          items:
            allOf:
              - $ref: '#/components/schemas/Person'
              - type: object
                required: [amountPaid, team, position]
                properties:
                  team: { type: [integer, 'null'], description: 'Side in an open match, 1 or 2; null otherwise.' }
                  position: { type: [integer, 'null'], description: 'Place within the team, 1 or 2; null otherwise.' }
                  amountPaid:
                    description: This player's part of `payment.amountPaid`; null when the booking is not priced.
                    oneOf: [{ $ref: '#/components/schemas/Money' }, { type: 'null' }]
        price:
          description: Total court price charged by the booking source; null when it does not price the booking.
          oneOf: [{ $ref: '#/components/schemas/Money' }, { type: 'null' }]
        payment:
          description: Money the booking source collected; null when it does not price the booking.
          oneOf:
            - type: object
              required: [status, amountPaid, amountRefunded, method]
              properties:
                status: { type: string, enum: [UNPAID, PARTIALLY_PAID, PAID, REFUNDED] }
                amountPaid:
                  $ref: '#/components/schemas/Money'
                  description: Money collected and not returned. The venue collects the rest of the price at the desk.
                amountRefunded:
                  $ref: '#/components/schemas/Money'
                  description: Money returned to the players.
                method: { type: [string, 'null'], description: For example CARD or WALLET. }
            - type: 'null'
        cancelledAt: { type: [string, 'null'], format: date-time, description: Null unless the booking is cancelled. }
        cancelledBy:
          type: [string, 'null']
          enum: [PLAYER, VENUE, PADEL_DESK, BOOKING_SOURCE, null]
          description: |
            Who cancelled the booking; null unless it is cancelled. BOOKING_SOURCE: the
            booking source itself, for example after a payment that failed.
        createdAt: { type: string, format: date-time }
        updatedAt: { type: string, format: date-time, description: Changes whenever any field of the booking changes. }

    Person:
      type: object
      required: [userId, name, phone, email]
      properties:
        userId: { type: [string, 'null'], description: Stable user id at the booking source; null for a guest. }
        name: { type: [string, 'null'] }
        phone: { type: [string, 'null'], description: E.164., examples: ['+905550000000'] }
        email: { type: [string, 'null'] }

    Court:
      type: object
      required: [id, name, active, reference]
      properties:
        id: { type: string }
        name: { type: string }
        active: { type: boolean, description: Whether the court can be booked. }
        reference: { type: [string, 'null'], description: Padel Desk's id of the court; null until a setup names it. }

    Setup:
      type: object
      required: [version, venue, openingHours, courts, prices]
      properties:
        version: { type: integer, format: int64, description: Increases with every change of the setup in Padel Desk. }
        venue:
          type: object
          required: [name, timezone, currency, address, location, phone, logoUrl, iconUrl]
          properties:
            name: { type: string }
            timezone: { type: string, description: IANA timezone., examples: [Europe/Istanbul] }
            currency: { type: string, description: ISO 4217., examples: [TRY] }
            address:
              type: [object, 'null']
              required: [line, city, country]
              properties:
                line: { type: string }
                city: { type: string }
                country: { type: string, description: ISO 3166-1 alpha-2., examples: [TR] }
            location:
              type: [object, 'null']
              required: [latitude, longitude]
              properties:
                latitude: { type: number }
                longitude: { type: number }
            phone: { type: [string, 'null'], description: E.164. }
            logoUrl: { type: [string, 'null'], format: uri, description: HTTPS link to the venue's logo. The booking source copies the image. }
            iconUrl: { type: [string, 'null'], format: uri, description: HTTPS link to a square icon. The booking source copies the image. }
        openingHours: { $ref: '#/components/schemas/OpeningHours' }
        courts:
          type: array
          items:
            type: object
            required: [reference, number, name, environment, format, active, durations, startStep]
            properties:
              reference: { type: string, maxLength: 191, description: Padel Desk's id of the court. Stable. }
              courtId:
                type: [string, 'null']
                description: |
                  The booking source's id of the court. Sent by Padel Desk for a court the
                  venue matched to an existing one; always present in responses.
              number: { type: integer, minimum: 1, description: Order of the court at the venue. }
              name: { type: string }
              environment: { type: string, enum: [INDOOR, OUTDOOR] }
              format: { type: string, enum: [DOUBLE, SINGLE] }
              active: { type: boolean, description: Whether the court can be booked. }
              durations:
                type: array
                minItems: 1
                items: { type: integer }
                description: 'Booking lengths the court accepts, in minutes.'
                examples: [[60, 90, 120]]
              startStep: { type: integer, description: 'Minutes between valid start times, counted from opening. A booking must end at or before the close.', examples: [30] }
        prices:
          type: array
          description: |
            Empty when the venue does not price bookings at the booking source. Otherwise:
            a rule covers a booking when the court, the weekday, the start time and the
            length all match. The weekday is that of the venue day, the day the venue opened:
            a booking at 01:00 after Friday's opening is a Friday booking. Two rules never
            cover the same booking; a setup where they do returns 422. A slot that no rule
            covers stays a slot, but the booking source does not offer it to players.
          items:
            type: object
            required: [courtReference, weekdays, from, to, duration, price]
            properties:
              courtReference: { type: string, description: '`reference` of a court in this document.' }
              weekdays: { type: array, items: { type: integer, minimum: 1, maximum: 7 }, description: 1 is Monday. }
              from: { type: string, description: 'Venue-local HH:mm; the rule applies to bookings that start at or after this time.' }
              to: { type: string, description: 'Venue-local HH:mm, exclusive; at or before `from` means the next day.' }
              duration: { type: integer, description: Booking length in minutes. }
              price: { $ref: '#/components/schemas/Money' }

    OpeningHours:
      type: array
      minItems: 7
      maxItems: 7
      description: One entry per weekday, Monday first; null on a day the venue is closed.
      items:
        type: [object, 'null']
        required: [open, close]
        properties:
          open: { type: string, description: 'Venue-local HH:mm.', examples: ['09:00'] }
          close: { type: string, description: 'Venue-local HH:mm; at or before `open` means the next day.', examples: ['03:00'] }

    Money:
      type: object
      required: [amountMinor, currency]
      properties:
        amountMinor: { type: integer, format: int64, description: Minor units; kuruş for TRY., examples: [180000] }
        currency: { type: string, description: ISO 4217., examples: [TRY] }

    Block:
      type: object
      required: [id, courtId, start, end, reason, origin, reference, removedAt, updatedAt]
      properties:
        id: { type: string }
        courtId: { type: string }
        start: { type: string, format: date-time }
        end: { type: string, format: date-time }
        reason: { type: [string, 'null'] }
        origin: { type: string, enum: [VENUE, PADEL_DESK] }
        reference: { type: [string, 'null'], description: Set only for blocks created through this API. }
        removedAt:
          type: [string, 'null']
          format: date-time
          description: Null unless the block is removed. A removed block no longer closes the court.
        updatedAt: { type: string, format: date-time }

    Event:
      type: object
      required: [id, sequence, type, createdAt, data]
      properties:
        id: { type: string, description: Unique per event; repeated deliveries carry the same id. }
        sequence:
          type: integer
          format: int64
          description: Increases with every event of the venue. A later change always has a higher sequence.
        type:
          type: string
          enum: [booking.created, booking.updated, booking.cancelled, block.created, block.updated, block.removed]
        createdAt: { type: string, format: date-time }
        data:
          description: The complete Booking or Block as it was when the event was created.
          oneOf:
            - $ref: '#/components/schemas/Booking'
            - $ref: '#/components/schemas/Block'
