import { Entity, Column, Index, ManyToOne, JoinColumn, OneToMany } from 'typeorm';
import { BaseEntity } from '../database/base.entity';
import { ActivityEntity } from './activity.entity';
import { ActivityTicketSlotEntity } from './activity-ticket-slot.entity';

/**
 * ActivityTicket entity — tenant-scoped child of Activity.
 *
 * Each activity can have multiple ticket types (e.g. General Admission, VIP, Fast Track).
 * Referenced by: Activity Pricing, Quotation, Booking modules.
 */
@Entity('activity_tickets')
@Index(['tenant_id', 'activity_id', 'name'], { unique: true, where: '"is_deleted" = false' })
export class ActivityTicketEntity extends BaseEntity {
  @ManyToOne(() => ActivityEntity, (activity) => activity.tickets, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'activity_id' })
  activity: ActivityEntity;

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

  @Column({ type: 'varchar', length: 255 })
  name: string;

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

  // time_slot dropped in migration 1781600000000 — slots are now in
  // the dedicated `activity_ticket_slots` child table so one ticket
  // can carry multiple disjoint windows.

  @Column({ type: 'int', nullable: true })
  duration_mins: number | null;

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

  @Column({ type: 'boolean', default: true })
  is_active: boolean;

  /** Time windows / departure times for this ticket. May be empty. */
  @OneToMany(() => ActivityTicketSlotEntity, (s) => s.ticket)
  slots: ActivityTicketSlotEntity[];
}
