import { Entity, Column, ManyToOne, JoinColumn } from 'typeorm';
import { BaseEntity } from '../database/base.entity';
import { BookingEntity } from './booking.entity';
import { ActivityEntity } from './activity.entity';
import { ActivityTicketEntity } from './activity-ticket.entity';
import { SupplierEntity } from './supplier.entity';

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

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

  @ManyToOne(() => ActivityEntity)
  @JoinColumn({ name: 'activity_id' })
  activity: ActivityEntity;

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

  @ManyToOne(() => ActivityTicketEntity, { nullable: true })
  @JoinColumn({ name: 'ticket_id' })
  ticket: ActivityTicketEntity | null;

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

  @Column({ type: 'varchar', length: 50 })
  age_group: string;

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

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

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

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

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

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

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

  // --- Supplier Assignment (Phase B — nullable for now) ---
  @ManyToOne(() => SupplierEntity, { nullable: true })
  @JoinColumn({ name: 'supplier_id' })
  supplier: SupplierEntity | null;

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

  // --- Ticket Upload (future — nullable for now) ---
  @Column({ type: 'varchar', length: 500, nullable: true })
  ticket_file_url: string | null;

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