import { Entity, Column, Index, ManyToOne, JoinColumn } from 'typeorm';
import { BaseEntity } from '../database/base.entity';
import { DestinationEntity } from './destination.entity';

/**
 * Season entity — tenant-scoped.
 *
 * Defines configurable seasons per destination (Peak, High, Shoulder, Low, Off-Peak).
 * Each destination × season has exactly one date range (start_date, end_date).
 * Used by Transport Pricing and Activity Pricing modules.
 */
@Entity('seasons')
@Index(['tenant_id', 'destination_id', 'name'], { unique: true, where: '"is_deleted" = false' })
export class SeasonEntity extends BaseEntity {
  @ManyToOne(() => DestinationEntity)
  @JoinColumn({ name: 'destination_id' })
  destination: DestinationEntity;

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

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

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

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

  /** Multiple date ranges for this season (e.g., Peak can occur 2-3 times per year) */
  @Column({ type: 'jsonb', nullable: true })
  durations: { start: string; end: string }[] | null;

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

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

  @Column({ type: 'boolean', default: false })
  is_system: boolean;
}
