import type { PostgresJsDatabase } from "drizzle-orm/postgres-js"; import type { BookingDocumentBundleItem, NotificationService, SendBookingDocumentsNotificationInput } from "./service-shared.js"; import type { NotificationAttachment } from "./types.js"; export type BookingDocumentAttachmentResolver = (document: BookingDocumentBundleItem) => Promise; export interface SendBookingDocumentsRuntimeOptions { attachmentResolver?: BookingDocumentAttachmentResolver; publicCustomerPortalBaseUrl?: string | null; } export interface BookingDocumentsSentEvent { bookingId: string; recipient: string; deliveryId: string; provider: string | null; documentKeys: string[]; } declare function createDefaultAttachmentFromDocument(document: BookingDocumentBundleItem): NotificationAttachment | null; export declare const bookingDocumentNotificationsService: { listBookingDocumentBundle(db: PostgresJsDatabase, bookingId: string): Promise<{ bookingId: string; documents: { key: string; source: "products" | "legal" | "finance"; documentType: "invoice" | "contract" | "proforma" | "brochure"; bookingId: string; name: string; createdAt: string; contractId?: string | null | undefined; invoiceId?: string | null | undefined; attachmentId?: string | null | undefined; renditionId?: string | null | undefined; contractStatus?: string | null | undefined; invoiceStatus?: string | null | undefined; format?: string | null | undefined; mimeType?: string | null | undefined; storageKey?: string | null | undefined; downloadUrl?: string | null | undefined; language?: string | null | undefined; metadata?: Record | null | undefined; }[]; } | null>; sendBookingDocumentsNotification(db: PostgresJsDatabase, dispatcher: NotificationService, bookingId: string, input: SendBookingDocumentsNotificationInput, runtime?: SendBookingDocumentsRuntimeOptions): Promise<{ status: "not_found"; bookingId?: undefined; recipient?: undefined; documents?: undefined; delivery?: undefined; } | { status: "no_documents"; bookingId?: undefined; recipient?: undefined; documents?: undefined; delivery?: undefined; } | { status: "no_recipient"; bookingId?: undefined; recipient?: undefined; documents?: undefined; delivery?: undefined; } | { status: "no_attachments"; bookingId?: undefined; recipient?: undefined; documents?: undefined; delivery?: undefined; } | { status: "send_failed"; bookingId?: undefined; recipient?: undefined; documents?: undefined; delivery?: undefined; } | { status: "pending"; bookingId: string; recipient: string; documents: { key: string; source: "products" | "legal" | "finance"; documentType: "invoice" | "contract" | "proforma" | "brochure"; bookingId: string; name: string; createdAt: string; contractId?: string | null | undefined; invoiceId?: string | null | undefined; attachmentId?: string | null | undefined; renditionId?: string | null | undefined; contractStatus?: string | null | undefined; invoiceStatus?: string | null | undefined; format?: string | null | undefined; mimeType?: string | null | undefined; storageKey?: string | null | undefined; downloadUrl?: string | null | undefined; language?: string | null | undefined; metadata?: Record | null | undefined; }[]; delivery: { bookingId: string | null; provider: string; id: string; channel: "email" | "sms"; status: "pending" | "sent" | "failed" | "cancelled"; fromAddress: string | null; metadata: Record | null; createdAt: Date; updatedAt: Date; templateId: string | null; templateSlug: string | null; targetType: "booking" | "booking_payment_schedule" | "booking_guarantee" | "invoice" | "payment_session" | "person" | "organization" | "other"; targetId: string | null; personId: string | null; organizationId: string | null; invoiceId: string | null; paymentSessionId: string | null; providerMessageId: string | null; toAddress: string; subject: string | null; htmlBody: string | null; textBody: string | null; payloadData: Record | null; errorMessage: string | null; scheduledFor: Date | null; sentAt: Date | null; failedAt: Date | null; }; }>; /** * Confirm-and-dispatch — single orchestrated call for the operator flow * that wants "list the booking's documents, then send them to the client" * to be one action instead of two round-trips. * * With `sendNotification: false`, the caller gets the bundle back without * attempting a send — useful for rendering a preview/checkbox list before * the operator confirms. With `sendNotification: true`, the same send * guards as `sendBookingDocumentsNotification` apply (no_documents, * no_recipient, no_attachments, send_failed); the result keeps the bundle * regardless so the UI always has something to show. */ confirmAndDispatchBooking(db: PostgresJsDatabase, dispatcher: NotificationService, bookingId: string, input: { sendNotification: false; documentTypes?: SendBookingDocumentsNotificationInput["documentTypes"]; } | ({ sendNotification?: true; } & SendBookingDocumentsNotificationInput), runtime?: SendBookingDocumentsRuntimeOptions): Promise<{ status: "not_found"; bookingId?: undefined; documents?: undefined; skipReason?: undefined; recipient?: undefined; delivery?: undefined; } | { status: "preview"; bookingId: string; documents: { key: string; source: "products" | "legal" | "finance"; documentType: "invoice" | "contract" | "proforma" | "brochure"; bookingId: string; name: string; createdAt: string; contractId?: string | null | undefined; invoiceId?: string | null | undefined; attachmentId?: string | null | undefined; renditionId?: string | null | undefined; contractStatus?: string | null | undefined; invoiceStatus?: string | null | undefined; format?: string | null | undefined; mimeType?: string | null | undefined; storageKey?: string | null | undefined; downloadUrl?: string | null | undefined; language?: string | null | undefined; metadata?: Record | null | undefined; }[]; skipReason?: undefined; recipient?: undefined; delivery?: undefined; } | { status: "skipped"; bookingId: string; documents: { key: string; source: "products" | "legal" | "finance"; documentType: "invoice" | "contract" | "proforma" | "brochure"; bookingId: string; name: string; createdAt: string; contractId?: string | null | undefined; invoiceId?: string | null | undefined; attachmentId?: string | null | undefined; renditionId?: string | null | undefined; contractStatus?: string | null | undefined; invoiceStatus?: string | null | undefined; format?: string | null | undefined; mimeType?: string | null | undefined; storageKey?: string | null | undefined; downloadUrl?: string | null | undefined; language?: string | null | undefined; metadata?: Record | null | undefined; }[]; skipReason: "no_documents" | "no_recipient" | "no_attachments" | "send_failed"; recipient?: undefined; delivery?: undefined; } | { status: "dispatched"; bookingId: string; documents: { key: string; source: "products" | "legal" | "finance"; documentType: "invoice" | "contract" | "proforma" | "brochure"; bookingId: string; name: string; createdAt: string; contractId?: string | null | undefined; invoiceId?: string | null | undefined; attachmentId?: string | null | undefined; renditionId?: string | null | undefined; contractStatus?: string | null | undefined; invoiceStatus?: string | null | undefined; format?: string | null | undefined; mimeType?: string | null | undefined; storageKey?: string | null | undefined; downloadUrl?: string | null | undefined; language?: string | null | undefined; metadata?: Record | null | undefined; }[]; recipient: string; delivery: { bookingId: string | null; provider: string; id: string; channel: "email" | "sms"; status: "pending" | "sent" | "failed" | "cancelled"; fromAddress: string | null; metadata: Record | null; createdAt: Date; updatedAt: Date; templateId: string | null; templateSlug: string | null; targetType: "booking" | "booking_payment_schedule" | "booking_guarantee" | "invoice" | "payment_session" | "person" | "organization" | "other"; targetId: string | null; personId: string | null; organizationId: string | null; invoiceId: string | null; paymentSessionId: string | null; providerMessageId: string | null; toAddress: string; subject: string | null; htmlBody: string | null; textBody: string | null; payloadData: Record | null; errorMessage: string | null; scheduledFor: Date | null; sentAt: Date | null; failedAt: Date | null; }; skipReason?: undefined; }>; }; export { createDefaultAttachmentFromDocument as createDefaultBookingDocumentAttachment };