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

@Entity({ schema: 'freight', name: 'weight_limit_rules' })
@Index(['containerTypeId'])
@Index(['tradeDirection'])
@Index(['effectiveFrom'])
export class WeightLimitRule extends BaseEntity {
  @Column({ name: 'container_type_id', type: 'uuid' })
  containerTypeId!: string;

  @ManyToOne(() => ContainerType, (ct) => ct.weightLimitRules)
  @JoinColumn({ name: 'container_type_id' })
  containerType!: ContainerType;

  @Column({ name: 'trade_direction', type: 'varchar', length: 10 })
  tradeDirection!: string;

  @Column({ name: 'max_vgm_tons', type: 'numeric', precision: 8, scale: 3, nullable: true })
  maxVgmTons!: number;

  @Column({ name: 'effective_from', type: 'date', nullable: true })
  effectiveFrom!: Date;

  @Column({ name: 'effective_to', type: 'date', nullable: true })
  effectiveTo?: Date | null;
}
