/**
 * Constants for Staff Dashboard Demo Bookings
 *
 * This module contains all constants, configuration values, and magic numbers
 * used in the demo bookings feature. Centralizing these makes the code easier
 * to maintain and change.
 *
 * @module lib/staff-dashboard/demo-bookings/constants
 */

/**
 * Table name for demo bookings
 *
 * @constant
 */
export const DEMO_BOOKINGS_TABLE = 'demo_bookings' as const;

/**
 * Maximum number of bookings to fetch in a single query
 *
 * This limit prevents performance issues and excessive memory usage.
 * Can be increased if needed, but consider pagination for large datasets.
 *
 * @constant
 * @default 100
 */
export const MAX_BOOKINGS_PER_QUERY = 100;

/**
 * Default booking status for new submissions
 *
 * @constant
 */
export const DEFAULT_BOOKING_STATUS = 'pending' as const;

/**
 * Valid booking status values
 *
 * @constant
 */
export const BOOKING_STATUSES = ['pending', 'confirmed', 'cancelled'] as const;

/**
 * Valid language values
 *
 * @constant
 */
export const LANGUAGES = ['ar', 'en'] as const;

/**
 * Valid date range filter values
 *
 * @constant
 */
export const DATE_RANGES = ['all', 'today', 'week', 'month'] as const;

/**
 * Number of days for each date range filter
 *
 * Used to calculate date boundaries when filtering.
 *
 * @constant
 */
export const DATE_RANGE_DAYS = {
  today: 0,  // Today only (from 00:00:00)
  week: 7,   // Last 7 days
  month: 30, // Last 30 days
} as const;

/**
 * Database field names (snake_case)
 *
 * Used for type-safe database queries and to avoid typos.
 *
 * @constant
 */
export const DB_FIELDS = {
  // Primary key
  ID: 'id',

  // Customer info
  FULL_NAME: 'full_name',
  EMAIL: 'email',
  TELEPHONE: 'telephone',

  // Appointment
  APPOINTMENT_DATE: 'appointment_date',
  APPOINTMENT_TIME: 'appointment_time',
  DURATION: 'duration',
  SPECIAL_REQUIREMENTS: 'special_requirements',

  // Metadata
  LANGUAGE: 'language',
  STATUS: 'status',

  // Webhook
  WEBHOOK_STATUS: 'webhook_status',
  WEBHOOK_RETRY_COUNT: 'webhook_retry_count',
  WEBHOOK_LAST_ATTEMPT: 'webhook_last_attempt',
  WEBHOOK_RESPONSE: 'webhook_response',

  // Staff management
  MEETING_LINK: 'meeting_link',
  INTERNAL_NOTES: 'internal_notes',
  CONTACTED_AT: 'contacted_at',
  CONTACTED_BY: 'contacted_by',

  // Timestamps
  CREATED_AT: 'created_at',
  UPDATED_AT: 'updated_at',
} as const;

/**
 * Searchable fields for the search filter
 *
 * These fields are searched when user enters text in the search box.
 *
 * @constant
 */
export const SEARCHABLE_FIELDS = [
  DB_FIELDS.FULL_NAME,
  DB_FIELDS.EMAIL,
  DB_FIELDS.TELEPHONE,
] as const;

/**
 * Error messages
 *
 * Centralized error messages for consistency across the application.
 *
 * @constant
 */
export const ERROR_MESSAGES = {
  UNAUTHORIZED: 'Unauthorized',
  BOOKING_ID_REQUIRED: 'Booking ID required',
  DATABASE_CONFIG_ERROR: 'Database configuration error',
  FETCH_FAILED: 'Failed to fetch bookings',
  UPDATE_FAILED: 'Failed to update booking',
  DATABASE_UNAVAILABLE: 'Database client not available',
} as const;

/**
 * Success messages
 *
 * @constant
 */
export const SUCCESS_MESSAGES = {
  BOOKING_UPDATED: 'Booking updated successfully',
  STATUS_CHANGED: 'Status updated successfully',
  MEETING_LINK_ADDED: 'Meeting link added successfully',
  NOTES_SAVED: 'Notes saved successfully',
} as const;

/**
 * Audit log configuration
 *
 * @constant
 */
export const AUDIT_CONFIG = {
  TYPE: 'staff_action',
  ACTION: 'Updated demo booking',
} as const;

/**
 * Query configuration
 *
 * @constant
 */
export const QUERY_CONFIG = {
  /** Default order direction for bookings list */
  DEFAULT_ORDER: 'created_at' as const,
  /** Order direction (newest first) */
  DEFAULT_ASCENDING: false,
  /** Default limit if not specified */
  DEFAULT_LIMIT: MAX_BOOKINGS_PER_QUERY,
} as const;

/**
 * Status badge colors for UI
 *
 * Maps status values to Tailwind CSS classes.
 *
 * @constant
 */
export const STATUS_BADGE_COLORS = {
  pending: 'bg-yellow-100 text-yellow-800',
  confirmed: 'bg-green-100 text-green-800',
  cancelled: 'bg-red-100 text-red-800',
} as const;

/**
 * Log prefixes for consistent logging
 *
 * @constant
 */
export const LOG_PREFIX = '[STAFF DASHBOARD]' as const;

/**
 * RLS policy information (for documentation)
 *
 * @constant
 */
export const RLS_POLICY_INFO = {
  READ: 'Only service_role can read demo bookings',
  UPDATE: 'Only service_role can update demo bookings',
  INSERT: 'Anyone can create demo bookings (public form)',
} as const;
