import { BaseEntity } from '@edr/api-common';
import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
import { Rate } from './rate.entity';

const TRIGGER_CONDITIONS = [
  'CARGO_FLAG_HAZARDOUS',
  'CARGO_FLAG_REEFER',
  'VGM_EXCEEDS_LIMIT',
  'SHIPPING_LINE_MAPPED',
  'CONSOLIDATION_ENABLED',
] as const;

export type TriggerCondition = typeof TRIGGER_CONDITIONS[number];

@Entity({ schema: 'freight', name: 'surcharge_types' })
@Index(['code'])
@Index(['isActive'])
@Index(['rateId'])
export class SurchargeType extends BaseEntity {
  @Column({ name: 'code', type: 'varchar', length: 40, unique: true })
  code!: string;

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

  @Column({ name: 'trigger_condition', type: 'varchar', length: 50, nullable: true })
  triggerCondition!: TriggerCondition;

  @Column({ name: 'rate_id', type: 'uuid', nullable: true })
  rateId!: string;

  @ManyToOne(() => Rate, { eager: false })
  @JoinColumn({ name: 'rate_id' })
  rate?: Rate;

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