import { type AvailabilitySlot } from "@voyant-travel/availability/schema"; import type { EventBus } from "@voyant-travel/core"; import type { PostgresJsDatabase } from "drizzle-orm/postgres-js"; import { type AvailabilitySlotChangedEvent } from "./events.js"; import type { AvailabilityCloseoutListQuery, AvailabilityRuleListQuery, AvailabilitySlotListQuery, AvailabilityStartTimeListQuery, CreateAvailabilityCloseoutInput, CreateAvailabilityRuleInput, CreateAvailabilitySlotInput, CreateAvailabilityStartTimeInput, UpdateAvailabilityCloseoutInput, UpdateAvailabilityRuleInput, UpdateAvailabilitySlotInput, UpdateAvailabilityStartTimeInput } from "./service-shared.js"; export type AvailabilitySlotWithEndDateLocal = AvailabilitySlot & { productName?: string | null; endDateLocal: string | null; }; export declare class AvailabilitySlotRevisionConflictError extends Error { readonly expectedUpdatedAt: string; readonly current: AvailabilitySlotWithEndDateLocal; constructor(expectedUpdatedAt: string, current: AvailabilitySlotWithEndDateLocal); } export declare function listRules(db: PostgresJsDatabase, query: AvailabilityRuleListQuery): Promise>; export declare function getRuleById(db: PostgresJsDatabase, id: string): Promise<{ id: string; productId: string; optionId: string | null; facilityId: string | null; timezone: string; recurrenceRule: string; maxCapacity: number; maxPickupCapacity: number | null; minTotalPax: number | null; cutoffMinutes: number | null; earlyBookingLimitMinutes: number | null; active: boolean; createdAt: Date; updatedAt: Date; } | null>; export declare function createRule(db: PostgresJsDatabase, data: CreateAvailabilityRuleInput): Promise<{ id: string; productId: string; optionId: string | null; facilityId: string | null; timezone: string; createdAt: Date; updatedAt: Date; recurrenceRule: string; maxCapacity: number; maxPickupCapacity: number | null; minTotalPax: number | null; cutoffMinutes: number | null; earlyBookingLimitMinutes: number | null; active: boolean; } | undefined>; export declare function updateRule(db: PostgresJsDatabase, id: string, data: UpdateAvailabilityRuleInput): Promise<{ id: string; productId: string; optionId: string | null; facilityId: string | null; timezone: string; recurrenceRule: string; maxCapacity: number; maxPickupCapacity: number | null; minTotalPax: number | null; cutoffMinutes: number | null; earlyBookingLimitMinutes: number | null; active: boolean; createdAt: Date; updatedAt: Date; } | null>; export declare function deleteRule(db: PostgresJsDatabase, id: string): Promise<{ id: string; } | null>; export declare function listStartTimes(db: PostgresJsDatabase, query: AvailabilityStartTimeListQuery): Promise>; export declare function getStartTimeById(db: PostgresJsDatabase, id: string): Promise<{ id: string; productId: string; optionId: string | null; facilityId: string | null; label: string | null; startTimeLocal: string; durationMinutes: number | null; sortOrder: number; active: boolean; createdAt: Date; updatedAt: Date; } | null>; export declare function createStartTime(db: PostgresJsDatabase, data: CreateAvailabilityStartTimeInput): Promise<{ id: string; productId: string; optionId: string | null; facilityId: string | null; createdAt: Date; updatedAt: Date; active: boolean; label: string | null; startTimeLocal: string; durationMinutes: number | null; sortOrder: number; } | undefined>; export declare function updateStartTime(db: PostgresJsDatabase, id: string, data: UpdateAvailabilityStartTimeInput): Promise<{ id: string; productId: string; optionId: string | null; facilityId: string | null; label: string | null; startTimeLocal: string; durationMinutes: number | null; sortOrder: number; active: boolean; createdAt: Date; updatedAt: Date; } | null>; export declare function deleteStartTime(db: PostgresJsDatabase, id: string): Promise<{ id: string; } | null>; export declare function listSlots(db: PostgresJsDatabase, query: AvailabilitySlotListQuery): Promise<{ data: AvailabilitySlotWithEndDateLocal[]; total: number; limit: number; offset: number; }>; export declare function getSlotById(db: PostgresJsDatabase, id: string): Promise<({ id: string; productId: string; itineraryId: string | null; optionId: string | null; facilityId: string | null; availabilityRuleId: string | null; startTimeId: string | null; dateLocal: string; startsAt: Date; endsAt: Date | null; timezone: string; status: "open" | "closed" | "sold_out" | "cancelled"; unlimited: boolean; initialPax: number | null; remainingPax: number | null; initialPickups: number | null; remainingPickups: number | null; remainingResources: number | null; pastCutoff: boolean; tooEarly: boolean; nights: number | null; days: number | null; notes: string | null; createdAt: Date; updatedAt: Date; } & { endDateLocal: string | null; }) | null>; export interface SlotMutationRuntime { /** * Optional event bus. When wired, slot create/update/delete each emit * `availability.slot.changed` so subscribers (channel-push, catalog * bridge) can react to any mutation that changes a product's effective * departure surface — not just operator edits. * * Per docs/architecture/channel-push-architecture.md §5.1. */ eventBus?: EventBus; /** * Origin of the change. `createSlot` / `deleteSlot` default to * `"created"` / `"deleted"`. `updateSlot` defaults to `"manual"`. The * scheduled-refresh job overrides with `"refresh"` so dashboards can * attribute drift correctly. */ source?: AvailabilitySlotChangedEvent["source"]; /** Test-only seams for deterministic concurrent-update coverage. */ testHooks?: { beforeSlotSnapshot?: (db: PostgresJsDatabase) => Promise; afterSlotSnapshot?: () => Promise; }; } /** * Back-compat alias for the original update-only runtime type. New * callers should reach for `SlotMutationRuntime`. */ export type UpdateSlotRuntime = SlotMutationRuntime; export declare function createSlot(db: PostgresJsDatabase, data: CreateAvailabilitySlotInput, runtime?: SlotMutationRuntime): Promise<({ id: string; productId: string; itineraryId: string | null; optionId: string | null; facilityId: string | null; availabilityRuleId: string | null; startTimeId: string | null; dateLocal: string; startsAt: Date; endsAt: Date | null; timezone: string; status: "open" | "closed" | "sold_out" | "cancelled"; unlimited: boolean; initialPax: number | null; remainingPax: number | null; initialPickups: number | null; remainingPickups: number | null; remainingResources: number | null; pastCutoff: boolean; tooEarly: boolean; nights: number | null; days: number | null; notes: string | null; createdAt: Date; updatedAt: Date; } & { endDateLocal: string | null; }) | undefined>; export declare function updateSlot(db: PostgresJsDatabase, id: string, data: UpdateAvailabilitySlotInput & { updatedAt?: string; }, runtime?: SlotMutationRuntime): Promise<({ id: string; productId: string; itineraryId: string | null; optionId: string | null; facilityId: string | null; availabilityRuleId: string | null; startTimeId: string | null; dateLocal: string; startsAt: Date; endsAt: Date | null; timezone: string; status: "open" | "closed" | "sold_out" | "cancelled"; unlimited: boolean; initialPax: number | null; remainingPax: number | null; initialPickups: number | null; remainingPickups: number | null; remainingResources: number | null; pastCutoff: boolean; tooEarly: boolean; nights: number | null; days: number | null; notes: string | null; createdAt: Date; updatedAt: Date; } & { endDateLocal: string | null; }) | null>; export declare function deleteSlot(db: PostgresJsDatabase, id: string, runtime?: SlotMutationRuntime): Promise<{ id: string; } | null>; export declare function listCloseouts(db: PostgresJsDatabase, query: AvailabilityCloseoutListQuery): Promise>; export declare function getCloseoutById(db: PostgresJsDatabase, id: string): Promise<{ id: string; productId: string; slotId: string | null; dateLocal: string; reason: string | null; createdBy: string | null; createdAt: Date; } | null>; export declare function createCloseout(db: PostgresJsDatabase, data: CreateAvailabilityCloseoutInput): Promise<{ id: string; productId: string; dateLocal: string; createdAt: Date; slotId: string | null; reason: string | null; createdBy: string | null; } | undefined>; export declare function updateCloseout(db: PostgresJsDatabase, id: string, data: UpdateAvailabilityCloseoutInput): Promise<{ id: string; productId: string; slotId: string | null; dateLocal: string; reason: string | null; createdBy: string | null; createdAt: Date; } | null>; export declare function deleteCloseout(db: PostgresJsDatabase, id: string): Promise<{ id: string; } | null>;