export type ReservationStatus =
  | "pending"
  | "confirmed"
  | "seated"
  | "completed"
  | "cancelled"
  | "no_show";

export type ReservationSource = "manual" | "whatsapp" | "web";

export interface Venue {
  id: number;
  name: string;
}

export interface VenueBookingSettings {
  venue_id: number;
  venue_name: string;
  turn_duration_minutes: number;
  whatsapp_enabled: boolean;
  whatsapp_assistant_prompt: string;
  whatsapp_assistant_base_prompt: string;
  whatsapp_assistant_effective_prompt: string;
  whatsapp_business_account_id: string;
  whatsapp_business_id: string;
  whatsapp_phone_number_id: string;
  whatsapp_display_phone_number: string;
  whatsapp_verified_name: string;
  whatsapp_access_token_configured: boolean;
  whatsapp_phone_number_id_saved: boolean;
  whatsapp_access_token_saved: boolean;
  whatsapp_uses_global_fallback: boolean;
}

export interface Room {
  id: number;
  venue_id: number;
  name: string;
  width: number;
  height: number;
  counter_name: string | null;
  counter_x: number | null;
  counter_y: number | null;
  counter_width: number | null;
  counter_height: number | null;
  counter_visible: boolean;
  entrance_name: string | null;
  entrance_x: number | null;
  entrance_y: number | null;
  entrance_width: number | null;
  entrance_height: number | null;
  entrance_visible: boolean;
  background_image_data_url: string | null;
}

export interface Table {
  id: number;
  room_id: number;
  name: string;
  x: number;
  y: number;
  width: number;
  height: number;
  shape: "square" | "round";
  rotation_degrees: number;
  min_seats: number;
  max_seats: number;
  join_group: string | null;
  is_active: boolean;
}

export interface Customer {
  id: number;
  name: string;
  phone: string;
  email: string | null;
  notes: string | null;
}

export interface TableCombination {
  id: number;
  room_id: number;
  name: string;
  table_ids: number[];
  min_seats: number;
  max_seats: number;
  is_active: boolean;
}

export interface Reservation {
  id: number;
  venue_id: number;
  customer_id: number;
  reservation_date: string;
  start_time: string;
  duration_minutes: number;
  guests: number;
  status: ReservationStatus;
  source: ReservationSource;
  notes: string | null;
  area_preference: string | null;
  assigned_table_id: number | null;
  assigned_combination_id: number | null;
  requires_table_join: boolean;
  service_summary: string | null;
  service_steps: string[];
  customer: Customer;
  assigned_table?: Table | null;
  assigned_combination?: TableCombination | null;
}

export interface ReservationListResponse {
  items: Reservation[];
  total: number;
}

export interface FloorPlanReservation {
  reservation_id: number;
  customer_name: string;
  guests: number;
  start_time: string;
  duration_minutes: number;
  status: ReservationStatus;
  assigned_table_id: number | null;
  assigned_combination_id: number | null;
  assignment_label: string | null;
  requires_table_join: boolean;
  service_summary: string | null;
  service_steps: string[];
}

export interface OccupancyWindow {
  reservation_id: number;
  customer_name: string;
  guests: number;
  status: ReservationStatus;
  start_time: string;
  end_time: string;
}

export interface TableFloorState {
  table_id: number;
  table_name: string;
  is_occupied_now: boolean;
  occupancy_windows: OccupancyWindow[];
}

export interface FloorPlanResponse {
  date: string;
  room: Room;
  tables: Table[];
  table_combinations: TableCombination[];
  reservations: FloorPlanReservation[];
  table_states: TableFloorState[];
}

export interface WhatsAppStatus {
  venue_id: number;
  venue_name: string;
  configured: boolean;
  phone_number_id_masked: string | null;
  phone_number_id: string;
  business_account_id: string;
  business_id: string;
  display_phone_number: string | null;
  verified_name: string | null;
  access_token_configured: boolean;
  phone_number_id_saved: boolean;
  access_token_saved: boolean;
  uses_global_fallback: boolean;
  verify_token_configured: boolean;
  app_secret_configured: boolean;
  graph_api_version: string;
  webhook_path: string;
  webhook_url: string;
  message: string;
}

export interface WhatsAppConfigValidation {
  success: boolean;
  phone_number_id: string;
  display_phone_number: string | null;
  verified_name: string | null;
  detail: string;
}

export interface WhatsAppSendTestResponse {
  success: boolean;
  recipient: string;
  message_id: string | null;
  detail: string;
}

export interface WhatsAppEventLog {
  id: number;
  event_type: string;
  contact_phone: string | null;
  wa_message_id: string | null;
  summary: string;
  payload: Record<string, unknown>;
  created_at: string;
}
