import { Entity, Column, Unique, ManyToOne, JoinColumn } from 'typeorm';
import { BaseEntity } from '../database/base.entity';
import { DestinationEntity } from './destination.entity';
import { TransportServiceEntity } from './transport-service.entity';
import { CurrencyEntity } from './currency.entity';

/**
 * Transport Pricing entity — tenant-scoped.
 *
 * Matrix: Transport Service × Category × Cab Type × 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('transport_pricing')
@Unique(['tenant_id', 'transport_service_id', 'cab_type', 'currency_id'])
export class TransportPricingEntity extends BaseEntity {
  @ManyToOne(() => DestinationEntity)
  @JoinColumn({ name: 'destination_id' })
  destination: DestinationEntity;

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

  @ManyToOne(() => TransportServiceEntity)
  @JoinColumn({ name: 'transport_service_id' })
  transport_service: TransportServiceEntity;

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

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

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

  @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;
}
