import { Entity, Column, ManyToOne, JoinColumn } from 'typeorm';
import { BaseEntity } from '../database/base.entity';
import { BookingEntity } from './booking.entity';
import { HotelEntity } from './hotel.entity';

@Entity('booking_hotel_items')
export class BookingHotelItemEntity extends BaseEntity {
  @ManyToOne(() => BookingEntity, (b) => b.hotel_items, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'booking_id' })
  booking: BookingEntity;

  @Column({ type: 'uuid' })
  booking_id: string;

  @ManyToOne(() => HotelEntity)
  @JoinColumn({ name: 'hotel_id' })
  hotel: HotelEntity;

  @Column({ type: 'uuid' })
  hotel_id: string;

  @Column({ type: 'varchar', length: 100, nullable: true })
  room_type: string | null;

  @Column({ type: 'varchar', length: 100, nullable: true })
  meal_plan: string | null;

  @Column({ type: 'date' })
  check_in_date: string;

  @Column({ type: 'date' })
  check_out_date: string;

  @Column({ type: 'int' })
  nights: number;

  @Column({ type: 'int', default: 1 })
  pax_per_room: number;

  @Column({ type: 'int', default: 1 })
  num_rooms: number;

  @Column({ type: 'int', default: 0 })
  aweb: number;

  @Column({ type: 'int', default: 0 })
  cweb: number;

  @Column({ type: 'int', default: 0 })
  cnb: number;

  @Column({ type: 'simple-json', nullable: true })
  nightly_rates: { date: string; rate: number }[] | null;

  @Column({ type: 'decimal', precision: 12, scale: 2, default: 0 })
  subtotal: number;

  @Column({ type: 'text', nullable: true })
  notes: string | null;
}
