# Spot — phase 1 contracts (what phase 2 builds on)

Read the code for exact signatures; this is the map. See also `docs/PLAN.md` (incl. "Deviations").

## Backend (A1)

- Enums `App\Enums\*` with `label()`, `values()`, `options()`. Extra: `ConflictType`, `ClosedReason`, `ConversationType`.
  `BookingStatus::isActive()/isClosed()/awaitingReply()`, `ShowStatus::isEditable()`.
- Models `App\Models\*` — every domain model has `scopeVisibleTo(User)`; use it in **every** controller query
  (lists, search, deep links). `redactFor(User $viewer)` on Show, Booking, Slot, Venue, User strips private fields for
  comedians — use it when serialising for a comedian. Factories exist for all main models
  (`User::factory()` = verified active comedian; states `manager()`, `deactivated()`, `unverified()`, `withWhatsapp()`).
- Policies `App\Policies\*` are complete; call `$this->authorize()` / `Gate` with the abilities there
  (e.g. Booking: `view`, `viewCurrentShow`, `viewShowDay`, `viewSnapshot`, `viewFee`, `message`, `withdraw`, `reassign`;
  OfferRevision: `view`, `accept`, `decline`; Slot: `sendOffer`, `reassign`, `viewCandidates`; User: `viewContact`,
  `deactivate`, `reactivate`, `message`; ExternalEngagement: `review`, `respondToRevision`). If an ability is truly
  missing, add a method — do not rewrite a policy file.
- Middleware aliases: `role:manager`, `role:comedian`, `active`. App routes: `['auth','verified','active']`.
- `App\Support\Actor::user($user, Channel::Web)` / `Actor::system()` is passed to every service call.
- Services (constructor-inject):
  - `Services\Booking\BookingWorkflow`: `sendOffer(Slot, User, Actor, array $options)`, `accept/decline(OfferRevision, User, Actor, ?reason, ?replyCode)`,
    `acceptWithCode/declineWithCode(User, code, Actor, ?reason)`, `withdraw`, `cancel`, `reassign(Slot, User, Actor, ?reason, array $options)`,
    `expire`, `updateDetails(Booking, ['instructions','manager_notes'], Actor)`, `snapshot`.
  - `Services\Booking\ConflictChecker`: `check`, `checkMany`, `candidatesForSlot(Slot)`, `venueOverlaps(Show)`; `ConflictReport::toArray()`.
  - `Services\Booking\ReplyCodes` (`mask()` for logs).
  - `Services\Shows\ShowService`: `create`, `previewImpact(Show, $changes): ImpactReport`, `update`, `reschedule`, `relocate`,
    `duplicateAsDraft`, `publish`, `cancel`, `complete`, `reorderSlots`, `addSlot`, `updateSlot`, `removeSlot`, `localToUtc($local, $tz)`.
  - `Services\Proposals\ProposalService`: `createBlock`, `submit`, `updateEngagement`, `withdraw`, `approve`, `decline`,
    `proposeRevision`, `acceptRevision`, `declineRevision`.
  - `Services\Availability\AvailabilityService`: `addDays`, `addDateRange`, `addLocalRange`, `addRange`, `update`, `remove`, `blockingBookings`.
  - `Services\ActivityLogger::log(Actor, action, ?subject, [...])`.
- Exceptions `App\Exceptions\Booking\*` extend `BookingException` (`errorKey`, `context`): `OfferExpired`, `OfferSuperseded`
  (has current revision id), `BookingConflict` (has report), `NotRecipient`, `InvalidReplyCode`,
  `ConfirmedTimeUnavailable` (`->bookings`), `InvalidTransition`. Controllers catch `BookingException` and turn it into a
  translated flash/validation error — never a 500.
- Events `App\Events\*` (after commit): `OfferSent`, `OfferRevised`, `OfferAccepted`, `OfferDeclined`, `OfferExpired`,
  `OfferWithdrawn`, `BookingReassigned`, `BookingCancelled`, `ShowCancelled`, `ShowLogisticsUpdated`, `ProposalSubmitted`,
  `ProposalReviewed`, `ProposalRevisionAnswered`, `MessageSent`. `OfferSent`/`OfferRevised` carry the plain `replyCode`
  — never log or store it unmasked. Only the comms package (B4) listens and notifies.
- `config/spot.php` for all tunables. Never call `env()` outside config files.
- Do not run bare `php artisan …` commands that touch the DB/cache: `.env` points at a MySQL server that is not yet
  authorised. Prefix with `DB_CONNECTION=sqlite DB_DATABASE=<file in your scratch dir> CACHE_STORE=array SESSION_DRIVER=file QUEUE_CONNECTION=sync`.
  Tests (`php artisan test`) are safe: SQLite in-memory.

## Frontend (A2)

- Pages live in `resources/js/pages/**` and get `AppLayout` automatically (sidebar on desktop, bottom tab bar on
  mobile, already padded `max-w-6xl px-4` — add no outer padding). `settings/*` pages get the settings sub-layout,
  `auth/*` the auth layout. Breadcrumbs: `defineOptions({ layout: { breadcrumbs: [{ title: 'common.nav.shows', href }] } })`.
  Title: `<Head :title="t('…')" />`.
- `useI18n()` → `{ t, tChoice, locale }`; keys are `group.dotted.key` from `lang/{it,en}/<group>.php`. Both locales must
  have identical keys (a parity test enforces it). Your group: see your brief. Reusable: `common.actions.*`,
  `common.words.*`, `common.form.*`, `common.empty.*`, `common.terms.fields.*`, `enums.<snake_enum>.<value>`.
- `useDateTime()` → `formatDate/Time/DateTime/Range(value, tz)`, `relativeDeadline`, `dayKey`, `isPast`, `crossesMidnight`.
- `components/spot/`: `StatusBadge` (`status`, `kind`), `EmptyState`, `ConfirmDialog` (`v-model:open`, `reason`, emits
  `confirm(reason)`), `PageHeader` (`title`, `description`, `back`, slot `actions`), `TermsDiff` (`oldTerms`, `newTerms`,
  `changedFields`, `timezone`), `DateTimeText`, `calendar/AgendaList|WeekGrid|MonthGrid`
  (`events: CalendarEvent[]`, `start`, `end` as `YYYY-MM-DD`; emit `select-date`, `select-event`, `navigate`).
  Types in `resources/js/types/spot.ts`. Read each component before using it.
- `components/ui/*`: shadcn-vue primitives (button, input, label, select, dialog, sheet, tabs, textarea, popover, card,
  badge, checkbox, dropdown-menu, …). Write new primitives by hand in the same style; avoid network installs.
- Shared props: `auth.user { id, name, email, role, timezone, locale }`, `counts { notifications, messages }`,
  `flash { success, error, info }` (plain props; for a toast use `Inertia::flash('toast', ['type' => 'success', 'message' => …])`).
- Navigation is in `resources/js/lib/navigation.ts` (already lists every URL in PLAN.md).
- Use Wayfinder-generated route helpers or plain URL strings — either is fine; forms use Inertia `useForm` / `<Form>`.
- Every screen: usable at 360 px with no horizontal scroll, labelled inputs, visible focus, status never by colour
  alone, empty states, inline validation errors, confirmation dialogs for destructive actions.
- Verify with `npm run types:check` and `php artisan test`. `npm run build` is run by several people at once — if it
  fails on a file that is not yours, ignore it and say so.
