/**
 * Staff Dashboard Demo Bookings Module
 *
 * This is the main entry point for the demo bookings feature.
 * It exports all utilities, types, and functions needed to work with demo bookings.
 *
 * ## Architecture
 *
 * The demo bookings feature is organized into focused modules:
 *
 * - **types.ts** - TypeScript type definitions
 * - **constants.ts** - Configuration values and magic numbers
 * - **mappers.ts** - Data transformation (snake_case ↔ camelCase)
 * - **queries.ts** - Database query builders
 * - **validators.ts** - Input validation
 * - **errors.ts** - Error handling and logging
 *
 * ## Database Architecture
 *
 * Demo bookings are stored in the database:
 * - Table: `demo_bookings`
 * - Naming: snake_case (database convention)
 *
 * ## Usage Examples
 *
 * ### Fetching Bookings
 *
 * ```typescript
 * import { fetchDemoBookings, mapBookingsToFrontend } from '@/lib/staff-dashboard/demo-bookings';
 *
 *
 * if (result.error) {
 *   return createDatabaseErrorResponse(result.error, 'fetch');
 * }
 *
 * const bookings = mapBookingsToFrontend(result.data);
 * return NextResponse.json({ bookings });
 * ```
 *
 * ### Updating Bookings
 *
 * ```typescript
 * import { updateDemoBooking, mapUpdateRequestToDatabase } from '@/lib/staff-dashboard/demo-bookings';
 *
 * const updateData = mapUpdateRequestToDatabase({
 *   status: 'confirmed',
 *   meetingLink: 'https://zoom.us/j/123'
 * }, staffUser.id);
 *
 * ```
 *
 * ### Validation
 *
 * ```typescript
 * import { validateUpdateRequest } from '@/lib/staff-dashboard/demo-bookings';
 *
 * const validation = validateUpdateRequest(req.body);
 * if (!validation.valid) {
 *   return createBadRequestResponse(validation.errors);
 * }
 * ```
 *
 * @module lib/staff-dashboard/demo-bookings
 */

// ============================================================================
// Type Definitions
// ============================================================================

export type {
  // Database types
  DemoBookingRecord,
  DemoBookingInput,
  DemoBookingUpdate,

  // Frontend/API types
  DemoBooking,
  DemoBookingUpdateRequest,
  DemoBookingsResponse,
  DemoBookingUpdateResponse,
  DemoBookingFilters,

  // Helper types
  StaffUser,
} from './types';

export { BookingStatus, WebhookStatus, Language, DateRange } from './types';

// ============================================================================
// Constants
// ============================================================================

export {
  // Table and limits
  DEMO_BOOKINGS_TABLE,
  MAX_BOOKINGS_PER_QUERY,

  // Enums
  BOOKING_STATUSES,
  LANGUAGES,
  DATE_RANGES,

  // Database fields
  DB_FIELDS,
  SEARCHABLE_FIELDS,

  // Messages
  ERROR_MESSAGES,
  SUCCESS_MESSAGES,

  // Configuration
  AUDIT_CONFIG,
  QUERY_CONFIG,
  RLS_POLICY_INFO,

  // UI
  STATUS_BADGE_COLORS,
  LOG_PREFIX,
} from './constants';

// ============================================================================
// Data Mappers
// ============================================================================

export {
  // Main mappers
  mapBookingToFrontend,
  mapBookingsToFrontend,
  mapUpdateRequestToDatabase,

  // Helper mappers
  mapFiltersToQueryParams,
  getDateRangeBoundary,
  mapDateToTimestamp,

  // Search utilities
  sanitizeSearchTerm,
  buildSearchPattern,
} from './mappers';

// ============================================================================
// Query Builders
// ============================================================================

export type { QueryResult } from './queries';

export {
  // Primary queries
  fetchDemoBookings,
  fetchDemoBookingById,
  updateDemoBooking,

  // Helper queries
  countBookingsByStatus,
  fetchRecentBookings,
  fetchPendingBookings,
  fetchBookingsByEmail,
  bookingExists,
  batchUpdateBookings,
} from './queries';

// ============================================================================
// Validators
// ============================================================================

export type { ValidationResult } from './validators';

export {
  // Validators
  isValidBookingId,
  isValidBookingStatus,
  isValidDateRange,
  isValidMeetingLink,
  validateUpdateRequest,
  validateFilters,
  sanitizeSearch,
} from './validators';

// ============================================================================
// Error Handlers
// ============================================================================

export {
  // Error class
  DemoBookingError,

  // Response creators
  createErrorResponse,
  createUnauthorizedResponse,
  createBadRequestResponse,
  createDatabaseErrorResponse,
  createSuccessResponse,

  // Error handlers
  handleDatabaseError,
  withErrorHandler,

  // Logging
  logOperation,
  logWarning,
  logSuccess,
} from './errors';
