import { BaseEntity } from '@edr/api-common';
import { Column, Entity, Index, OneToMany } from 'typeorm';
import { WeightLimitRule } from './weight-limit-rule.entity';

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

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

  @Column({ name: 'size_ft', type: 'smallint', nullable: true })
  sizeFt!: number;

  @Column({ name: 'wagons_per_unit', type: 'numeric', precision: 4, scale: 2, nullable: true })
  wagonsPerUnit!: number;

  @Column({ name: 'is_reefer', type: 'boolean', default: false, nullable: true })
  isReefer!: boolean;

  @Column({ name: 'is_open_top', type: 'boolean', default: false, nullable: true })
  isOpenTop!: boolean;

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

  @Column({ name: 'display_order', type: 'int', default: 1, nullable: true })
  displayOrder!: number;

  @OneToMany(() => WeightLimitRule, (rule) => rule.containerType)
  weightLimitRules?: WeightLimitRule[];
}
