export type InventoryType = "EXCHANGE" | "RENTAL";

export type BedroomType =
  "Hotel" | "Studio" | "1 Bedroom" | "2 Bedroom" | "3 Bedroom" | "4 Bedroom";

export type GuestType = "OWNER" | "FAMILY";

export type ChargeType =
  "ADDITIONAL_CHARGE" | "POINTS" | "PROCESSING_FEE" | "GUEST_CERTIFICATE_FEE";

export type PaymentMethod =
  "CREDIT_CARD" | "DEBIT_CARD" | "NET_BANKING" | "UPI" | "WALLET";

export interface AdditionalData {
  [key: string]: string | number | boolean;
}

export interface CreateBookingGuest {
  contactID: string;
  isPrimaryGuest: boolean;
  type: GuestType;
  sendBookingConfirmation: boolean;
  additional_data: {
    special_requests: string;
    has_travel_insurance: string;
    is_pet_travelling: string;
    medical_mobility_requirements: string;
  };
}

export interface CreateBookingCharge {
  currency: string;
  value: number;
  type: ChargeType;
  name: string;
}

export interface CreateBookingUnit {
  bedroom_type: BedroomType;
  note: string;
  additionalData: AdditionalData;
  guests: CreateBookingGuest[];
  adults: number;
  children: number;
  infants: number;
  externalBooking: {
    refID: string;
    additionalData: AdditionalData;
  };
  checkInDate: string;
  checkOutDate: string;
  charges: CreateBookingCharge[];
}

export interface CreateBookingPaymentDetails {
  amount: number;
  currency: string;
  ref_id: string;
  method_name: PaymentMethod;
  gateway_name: string;
}

export interface CreateBookingFormData {
  memberRecordID: string;
  resort: {
    rciResortCode: string;
    additionalData: {
      partner: string;
    };
  };
  inventoryType: InventoryType;
  units: CreateBookingUnit[];
  bookedAt: string;
  bookingSource: string;
  note: string;
  additionalData: AdditionalData;
  paymentDetails: CreateBookingPaymentDetails;
}

export const CHARGE_TYPE_ORDER: ChargeType[] = [
  "ADDITIONAL_CHARGE",
  "POINTS",
  "PROCESSING_FEE",
  "GUEST_CERTIFICATE_FEE",
];

export const CHARGE_TYPE_SELECT_OPTIONS = [
  { value: "ADDITIONAL_CHARGE" as const, label: "Additional Charge" },
  { value: "POINTS" as const, label: "Points/Entitlements" },
  { value: "PROCESSING_FEE" as const, label: "Processing Fee" },
  { value: "GUEST_CERTIFICATE_FEE" as const, label: "Guest Certificate Fee" },
];

export const CHARGE_NAME_OPTIONS = [
  { value: "Additional Charge", label: "Additional Charge" },
  { value: "Entitlements", label: "Entitlements" },
  { value: "Processing Fee", label: "Processing Fee" },
  { value: "Guest Certificate Fee", label: "Guest Certificate Fee" },
];

export const CHARGE_NAME_BY_TYPE: Record<ChargeType, string> = {
  ADDITIONAL_CHARGE: "Additional Charge",
  POINTS: "Entitlements",
  PROCESSING_FEE: "Processing Fee",
  GUEST_CERTIFICATE_FEE: "Guest Certificate Fee",
};

export const CHARGE_DEFAULT_CURRENCY: Record<ChargeType, string> = {
  ADDITIONAL_CHARGE: "INR",
  POINTS: "",
  PROCESSING_FEE: "INR",
  GUEST_CERTIFICATE_FEE: "INR",
};

export const createDefaultCharge = (type: ChargeType) => ({
  type,
  value: 0,
  currency: CHARGE_DEFAULT_CURRENCY[type],
  name: CHARGE_NAME_BY_TYPE[type],
});

export const DEFAULT_UNIT_CHARGES = CHARGE_TYPE_ORDER.map(createDefaultCharge);
