import { Entity, Column, Unique, ManyToOne, JoinColumn } from 'typeorm';
import { BaseEntity } from '../database/base.entity';
import { DestinationEntity } from './destination.entity';
import { ActivityEntity } from './activity.entity';
import { ActivityTicketEntity } from './activity-ticket.entity';
import { CurrencyEntity } from './currency.entity';

export enum AgeGroup {
  CHILD = 'child',
  ADULT = 'adult',
  SENIOR = 'senior',
}

/**
 * Activity Pricing entity — tenant-scoped.
 *
 * Matrix: Activity × Ticket Type × Age Group × Currency → Default + 5 Seasonal Prices.
 * Season columns are positional (1-5 by sort_order from Season Master).
 * Auto-fetched in quotations by matching travel date to SeasonDuration ranges.
 */
@Entity('activity_pricing')
@Unique(['tenant_id', 'activity_id', 'ticket_id', 'age_group', 'currency_id'])
export class ActivityPricingEntity extends BaseEntity {
  @ManyToOne(() => DestinationEntity)
  @JoinColumn({ name: 'destination_id' })
  destination: DestinationEntity;

  @Column({ type: 'uuid' })
  destination_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: AgeGroup;

  @ManyToOne(() => CurrencyEntity)
  @JoinColumn({ name: 'currency_id' })
  currency: CurrencyEntity;

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

  @Column({ type: 'decimal', precision: 12, scale: 2, nullable: true })
  default_price: number | null;

  @Column({ type: 'decimal', precision: 12, scale: 2, nullable: true })
  season_1_price: number | null;

  @Column({ type: 'decimal', precision: 12, scale: 2, nullable: true })
  season_2_price: number | null;

  @Column({ type: 'decimal', precision: 12, scale: 2, nullable: true })
  season_3_price: number | null;

  @Column({ type: 'decimal', precision: 12, scale: 2, nullable: true })
  season_4_price: number | null;

  @Column({ type: 'decimal', precision: 12, scale: 2, nullable: true })
  season_5_price: number | null;
}
