# stapel-reservations 0.1.0

Schedules, free slots and reservations over opaque bookables. A host registers what can be booked (bookable_type -> a keyed-batch resolver Function answering title, price, currency, availability and the provider's seller_id — the listings.purchasables contract, so a service listing is bookable with no change to listings). Each bookable has a schedule of weekly rules in a named time zone, dated exceptions, duration, capacity, lead time, horizon and a cancellation window; until its provider saves one it offers DEFAULT_SCHEDULE. Free slots are computed on read with zero comm calls. A booking is idempotent on a client key and re-counts the slot under a lock on the schedule row, so two customers racing for the last seat end as one reservation and one slot_full. Reservations follow a table FSM (auto- or manual confirmation, customer cancel inside the window, provider confirm/cancel/no-show, completion by beat); payment is a provider seam (none, mock) whose outcome arrives as the reservations.payment.completed fact (or the payment module's payment.completed).

Contract: axes 5 · surface 13 · extension points 9 · operations 9 · error codes 64 · flows 3.
Generated from docs/capabilities.json by `stapel-llms-txt` — do not edit; drift-gated by `make contract-check`.

## Configuration axes — what a product switches on
Settings keys; `default` is what you get by saying nothing. Turning an axis off unmounts the operations it gates.
- AUTO_CONFIRM [bool, default true] — Confirm bookings by hand
  true (default): a booking is confirmed at once. false: it waits as pending until the provider confirms it from the agenda (it still holds the slot). Values: true, false.
- BOOKING_REQUIRES_ACCOUNT [bool, default true] — Guest booking
  Whether a customer must have an account to book. true (default): a guest sees the free slots but is asked to sign in to book. false: guests can book too. Values: true, false.
- DEFAULT_SCHEDULE.capacity [enum, default 1] — Places per slot
  How many customers one slot takes before it is full, for every bookable that has not saved its own schedule: 1 (default) is a one-to-one appointment, 12 is a class of twelve. Set as STAPEL_RESERVATIONS = {"DEFAULT_SCHEDULE": {"capacity": n}}; the rest of the default schedule is kept. Values: 1-1000.
- DEFAULT_SCHEDULE_ENABLED [bool, default true] — Bookable before hours are set
  true (default): every bookable offers DEFAULT_SCHEDULE (weekdays 09:00-18:00 UTC, one-hour slots) until its provider saves a schedule, so a fresh booking site works on day one. false: nothing is offered until a schedule is saved. Values: true, false.
- PAYMENT [enum, default "none"] — How bookings are paid
  none (default): priced reservations stay unpaid (paid on site). mock: every priced reservation is marked paid at once with no money moving, for prototypes only. A real payment provider registers its own name. Values: none, mock.

## Usage surface — call these before writing your own
This is the answer to "does Stapel already have something for X?". `instead of` names the outside symbol this one displaces.
### gate_function
- resolve — stapel_reservations.registry.resolve
  Resolve keys of one type in one call through the transport, validated against the bookables contract. Raises ResolverUnavailable instead of guessing; reservations answers 503 on it.
- resolve_one — stapel_reservations.registry.resolve_one
  resolve() for a single key; None when the resolver does not know it.
### predicate
- get_bookable_types — stapel_reservations.registry.get_bookable_types
  The effective registry (built-ins <- settings <- runtime). Ask it instead of reading the setting, which misses runtime registrations.
- is_registered — stapel_reservations.registry.is_registered
  Is a bookable type registered with a resolver? The slot and schedule reads answer error.400.bookable_type_unknown when not.
- payment_names — stapel_reservations.payment.payment_names
  The short names PAYMENT accepts; also the environment vocabulary.
- resolver_name — stapel_reservations.registry.resolver_name
  The comm Function name that resolves a type, or UnknownBookableType.
### factory
- active_provider — stapel_reservations.payment.active_provider
  The provider this deployment runs (reservations_settings.PAYMENT).
- payment_completed_payload — stapel_reservations.payment.payment_completed_payload
  Build the reservations.payment.completed payload a PAYMENT provider emits when a reservation is paid in full (user_id null for a guest, simulated for test money). Reach for it in a provider instead of emitting the payment module's payment.completed.
- register_bookable_type — stapel_reservations.registry.register_bookable_type
  Declare a bookable type and its resolver Function from an AppConfig.ready() (or a test). The registry ships empty; this and STAPEL_RESERVATIONS['BOOKABLE_TYPES'] are the only two ways in, and both replace hand-building a booking model for a custom resource. entry=None removes a type a lower layer provided.
- register_payment_provider — stapel_reservations.payment.register_payment_provider
  Register a payment provider under a short name PAYMENT (and the environment) may then choose. The provider starts a payment in the booking transaction; the outcome arrives as reservations.payment.completed (or the payment module's payment.completed).
- reset_bookable_types — stapel_reservations.registry.reset_bookable_types
  Drop runtime registrations, leaving settings untouched — a test lever. Product code calling it is undoing a registration that belongs in settings.
- reset_payment_providers — stapel_reservations.payment.reset_payment_providers
  Drop registered providers — a test lever.
- resolve_payment — stapel_reservations.payment.resolve_payment
  Turn a PAYMENT value (short name or dotted path) into a provider; the AppSettings resolver for the key.

## Extension points — what a product replaces, fork-free
- AMOUNT_BASE_CONVERTER [strategy]
  Dotted path (amount, currency, base) -> Decimal | None computing Reservation.amount_base for reporting. Default asks currencies.convert by name; no answer stores NULL, never a guess.
- BOOKABLE_TYPES [merge_registry]
  What can be booked. {type_name: {'resolve': '<comm function>'}} merged over the empty built-ins; None removes a type. The resolver is one keyed batch for every type ({keys} -> {key: {title, price, currency, available, max_quantity, seller_id, image, url}}); price null books a free reservation. A custom app registers its bookable in about twenty lines and reservations never imports its model.
- DEFAULT_SCHEDULE [setting]
  The schedule every bookable offers until its provider saves one (time zone, duration, step, capacity, lead time, horizon, cancellation window, weekly rules; the PUT schedule/ body shape). Validated at boot (check E005).
- PAYMENT [strategy]
  How a priced reservation is paid: a short name from the payment registry (none, mock, plus register_payment_provider names) or a dotted path. The provider starts a payment inside the booking transaction; the outcome arrives as reservations.payment.completed (or the payment module's payment.completed), the only path that marks a reservation paid.
- STAPEL_RESERVATIONS_RESERVATION_PRESENTER / STAPEL_RESERVATIONS_SCHEDULE_PRESENTER / STAPEL_RESERVATIONS_SLOTS_PRESENTER [presenter]
  Swap keys (STAPEL_SWAP) for the reservation, schedule and slots response presenters, so a host changes what the API shows without forking a view.
- payment.completed [comm_event]
  Consumed, never emitted (the payment module owns it): reference_type 'reservation' marks the reservation paid when amount and currency match, and sends it to needs_review when they do not.
- reservations.payment.completed [comm_event]
  Emitted by the PAYMENT providers registered here (the mock with simulated true); user_id is null for a guest. Consumed by this module like payment.completed.
- reservations.reservation.booked [comm_event]
  A slot was booked: reservation, customer, provider, bookable, start/end, amount, status — never contact fields — so a calendar can mirror it and a provider can be told.
- reservations.reservation.status_changed [comm_event]
  Every lifecycle move, with the actor (customer, provider, staff, system) and an optional reason.

## Fits with — fleet dependencies
- stapel-auth (optional) — reservations are keyed on request.user, and a guest is a stapel-auth anonymous account; user.merged moves a guest's reservations to the account on sign-in
- stapel-core (required) — comm bus (reservations.* emits, resolver and status Functions, user.merged and payment.completed consumers), AnchorPagination, GDPR owner protocol, posture stage, AppSettings
- stapel-currencies (optional) — currencies.convert fills Reservation.amount_base for reporting; without it amount_base stays NULL
- stapel-listings (optional) — answers listings.bookables (0.29+, unpriced listings included), the resolver of the 'listing' bookable type the stapel-booking preset registers
- stapel-notifications (optional) — delivers reservations.booked, reservations.status_changed, reservations.reminder and reservations.new_for_provider

## HTTP operations (9) — call by operationId, never by a typed path
Paths are relative to `/reservations/api/v1/`.
### Reservations
- GET /provider/agenda/ — reservations_agenda_list
- POST /provider/reservations/{reservation_id}/transition/ — reservations_provider_transition
- POST /reservations/{reservation_id}/cancel/ — reservations_reservations_cancel
- POST /reservations/ — reservations_reservations_create
- GET /reservations/ — reservations_reservations_list
- GET /reservations/{reservation_id}/ — reservations_reservations_retrieve
- GET /bookables/{bookable_type}/{bookable_key}/schedule/ — reservations_schedule_retrieve
- PUT /bookables/{bookable_type}/{bookable_key}/schedule/ — reservations_schedule_update
- GET /bookables/{bookable_type}/{bookable_key}/slots/ — reservations_slots_list

## Error codes (64) — the StapelError envelope
Render `t(code, params)`; branch UX on the remediation. Localized text lives in docs/errors.<lang>.md, not here.
- error.400.bad_request [400] fix_input
- error.400.bookable_type_unknown [400] fix_input
- error.400.bookable_unknown [400] fix_input
- error.400.captcha_invalid [400] retry
- error.400.captcha_required [400] retry
- error.400.expected_list [400] fix_input
- error.400.field.blank [400] fix_input {field}
- error.400.field.does_not_exist [400] fix_input {field}
- error.400.field.invalid [400] fix_input {field}
- error.400.field.invalid_choice [400] fix_input {field}
- error.400.field.max_length [400] fix_input {field,max_length}
- error.400.field.max_value [400] fix_input {field,max_value}
- error.400.field.min_length [400] fix_input {field,min_length}
- error.400.field.min_value [400] fix_input {field,min_value}
- error.400.field.null [400] fix_input {field}
- error.400.field.required [400] fix_input {field}
- error.400.field.unique [400] fix_input {field}
- error.400.invalid_ad_id [400] fix_input
- error.400.range_exceeds_horizon [400] fix_input {horizon_days}
- error.400.schedule_exception_duplicate [400] fix_input
- error.400.schedule_invalid_timezone [400] fix_input
- error.400.schedule_rules_overlap [400] fix_input
- error.400.schedule_window_invalid [400] fix_input
- error.400.slot_range_invalid [400] fix_input {max_days}
- error.400.start_in_past [400] fix_input
- error.400.start_not_on_grid [400] fix_input
- error.400.too_many_ids [400] fix_input {requested,limit}
- error.400.validation_error [400] fix_input
- error.400.verification_failed [400] verify
- error.400.verification_invalid_factor [400] verify
- error.401.unauthorized [401] reauthenticate
- error.402.payment_required [402] retry
- error.403.booking_requires_account [403] reauthenticate
- error.403.forbidden [403] retry
- error.403.network_blocked [403] contact_support
- error.403.provider_requires_account [403] reauthenticate
- error.403.verification_enrollment_required [403] verify
- error.403.verification_required [403] verify
- error.404.ad_not_found [404] retry
- error.404.bookable_not_found [404] retry
- error.404.not_found [404] retry
- error.404.reservation_not_found [404] retry
- error.404.verification_challenge_not_found [404] verify
- error.405.method_not_allowed [405] retry
- error.406.not_acceptable [406] retry
- error.408.request_timeout [408] retry
- error.409.bookable_unavailable [409] fix_input
- error.409.cancellation_window_closed [409] fix_input
- error.409.conflict [409] fix_input
- error.409.reservation_transition_invalid [409] fix_input {from,to}
- error.409.slot_full [409] retry
- error.409.slot_not_offered [409] fix_input
- error.410.gone [410] retry
- error.413.payload_too_large [413] retry
- error.415.unsupported_media_type [415] retry
- error.422.unprocessable_entity [422] wait_and_retry
- error.423.locked [423] wait_and_retry
- error.423.verification_locked [423] wait_and_retry
- error.429.rate_limit [429] wait_and_retry {retry_after_display,retry_after,retry_after_minutes}
- error.429.too_many_active_reservations [429] wait_and_retry {max}
- error.429.too_many_requests [429] wait_and_retry
- error.500.internal [500] contact_support
- error.503.bookable_unavailable [503] wait_and_retry
- error.503.mandate_unavailable [503] retry

## Documented flows (3) — full steps in docs/flows.json
- reservations.book — Book a time slot
- reservations.mine — Follow my reservations
- reservations.provider — Run a bookable's agenda
