import type { Destination } from "../destination/types";
import type { VpContactDetails } from "../members/types";

export type CoreBookingEntity =
  "RCI_EXCHANGE" | "RCI_RENTALS" | "RESORT" | "EVENT";

export type CoreBookingStatus =
  | "CHECKED_IN"
  | "CHECKED_OUT"
  | "ENDED"
  | "FAILED"
  | "HOLD"
  | "SELF_CANCELLED"
  | "SYSTEM_CANCELLED"
  | "SYSTEM_FAULT"
  | "SYSTEM_PROCESSING"
  | "UPCOMING";

export interface CoreBookingUnit {
  id: string;
  status: CoreBookingStatus;
  adults: number;
  children: number;
  complete_source: string;
  hold_end: string;
  hold_expiration: string;
  hold_start: string;
  infants: number;
  unit_code: string;
  unit_name: string;
  completed_at: string;
  viewpoint_booking_number: string;
  check_in_date: string;
  check_out_date: string;
  booking_id: string;
  entity_type: CoreBookingEntity;
  entity_id: number;
  member_id: string;
  _is_deleted: boolean;
  destination: Destination;
}

export interface CoreBookingUnitGuest {
  id: number;
  member_number: string;
  type: string;
  member_id?: number | null;
  details: VpContactDetails;
}

export type CoreBookingChargeType =
  "GUEST_CERTIFICATE_FEE" | "POINTS" | "ADDITIONAL_CHARGE";

export interface CoreBookingUnitCharge {
  id: 4;
  currency: string;
  type: CoreBookingChargeType;
  name: string;
  value: number;
}

export interface CoreBookingUnitDetailed {
  id: string;
  status: CoreBookingStatus;
  adults: number;
  children: number;
  complete_source: string | null;
  hold_end: string | null;
  hold_expiration: string;
  hold_start: string;
  infants: number;
  unit_code: string;
  unit_name: string;
  completed_at: string | null;
  viewpoint_booking_number: string;
  check_in_date: string;
  check_out_date: string;
  hold_source: string;
  ext_src_additional_data: {
    inventory_type: "EXCHANGE" | "RENTAL";
    reference_number: string;
    reservation_inventory_type: number;
  };
  ext_src_name: string;
  ext_src_ref_id: string;
  created_at: string;
  note: string | null;
  additional_data: {
    special_requests?: string;
  };
  booking_ext_ref_id: string;
  external_booking_source: {
    additional_data: {
      inventory_type: "EXCHANGE" | "RENTAL";
      reference_number: string;
      reservation_inventory_type: number;
    };
    source_name: string;
    ref_id: string;
  };
  guests: CoreBookingUnitGuest[];
  charges: CoreBookingUnitCharge[];
}

export type CorePaymentStatus =
  "CANCELLED" | "COMPLETED" | "FAILED" | "PENDING" | "REFUNDED";

export interface CorePaymentTransactions {
  id: number;
  method: string;
  currency: string;
  total_amount: string;
  gateway: string;
  source_type: string;
  status: CorePaymentStatus;
  additional_data: Record<string, unknown>;
  ref_id: string;
  created_at: string;
}

export interface CoreBooking {
  id: string;
  entity_id: string;
  entity_type: CoreBookingEntity;
  member_id: string;
  _is_deleted: false;
  additional_data: {
    is_pet_travelling: string;
    has_travel_insurance: string;
    medical_mobility_requirements?: string;
  };
  destination: {
    id: string;
    code: string;
    name: string;
    additional_data: {
      special_requests?: string;
    };
    created_at: string;
    updated_at: string | null;
  };
  units: CoreBookingUnitDetailed[];
  payments: CorePaymentTransactions[];
}

export interface CoreResponse {
  success: boolean;
  message?: string;
  data?: any;
}
