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

/**
 * ActivityTicketSlot — one availability window per row.
 *
 * Tickets like Ain Dubai "Non-Prime Time" carry two disjoint windows
 * (10:00 AM-4 PM AND 7:30-8 PM) — the parent ticket's old `time_slot`
 * varchar couldn't model that. Each slot row is one window OR one
 * departure time.
 *
 * `label` is what ops/customer sees verbatim. `start_time` /
 * `end_time` are best-effort 24h parses; both can be NULL when the
 * source label is prose or ambiguous.
 *
 * Unique on (tenant_id, ticket_id, label) so re-imports / re-seeds
 * don't duplicate rows.
 */
@Entity('activity_ticket_slots')
@Index(['tenant_id', 'ticket_id'], { where: '"is_deleted" = false' })
@Index(['tenant_id', 'ticket_id', 'label'], { unique: true, where: '"is_deleted" = false' })
export class ActivityTicketSlotEntity extends BaseEntity {
  @ManyToOne(() => ActivityTicketEntity, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'ticket_id' })
  ticket: ActivityTicketEntity;

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

  @Column({ type: 'varchar', length: 100 })
  label: string;

  /** 24h HH:MM:SS. NULL when source label is prose. */
  @Column({ type: 'time', nullable: true })
  start_time: string | null;

  /** NULL for single-departure slots (e.g. Yellow Boat 09:00). */
  @Column({ type: 'time', nullable: true })
  end_time: string | null;

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