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

/**
 * DestinationVehicleType — join table linking destinations to the
 * vehicle types available there.
 *
 * Use case: stakeholder ask (2026-05-27). Each destination has its own
 * fleet mix. Cars available in Dubai differ from those in Goa. This
 * mapping powers the vehicle-type dropdown in Quote/Booking transport
 * rows and the Movement Chart's vehicle assignment.
 *
 * Unique constraint: one row per (tenant, destination, vehicle_type)
 * — duplicates make no sense. Tenant-scoped via the standard column on
 * BaseEntity; the unique index includes tenant_id explicitly so two
 * different tenants don't trip the constraint.
 */
@Entity('destination_vehicle_types')
@Index(['tenant_id', 'destination_id', 'vehicle_type_id'], {
  unique: true,
  where: '"is_deleted" = false',
})
@Index(['tenant_id', 'destination_id']) // hot-path filter
export class DestinationVehicleTypeEntity extends BaseEntity {
  @ManyToOne(() => DestinationEntity)
  @JoinColumn({ name: 'destination_id' })
  destination: DestinationEntity;

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

  @ManyToOne(() => VehicleTypeEntity)
  @JoinColumn({ name: 'vehicle_type_id' })
  vehicle_type: VehicleTypeEntity;

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