import { BaseEntity } from '@edr/api-common';
import { Column, Entity, Index, OneToMany } from 'typeorm';

import { TrainSetWagon } from '../../train-sets/entities/train-set-wagon.entity';

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

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

  @Column({ name: 'capacity_tons', type: 'numeric', precision: 10, scale: 3 })
  capacityTons!: number;

  @Column({ name: 'length_meters', type: 'numeric', precision: 10, scale: 3 })
  lengthMeters!: number;

  @Column({ name: 'max_wagons_per_train', type: 'int', nullable: true })
  maxWagonsPerTrain?: number | null;

  @Column({ name: 'supported_load_types', type: 'text', array: true, default: '{}' })
  supportedLoadTypes!: string[];

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

  @Column({ name: 'equated_length_m', type: 'numeric', precision: 10, scale: 3, nullable: true })
  equatedLengthM?: number | null;

  @Column({ name: 'tare_weight_tons', type: 'numeric', precision: 10, scale: 3, nullable: true })
  tareWeightTons?: number | null;

  @Column({ name: 'supports_container', type: 'boolean', default: false })
  supportsContainer!: boolean;

  @Column({ name: 'max_container_gross_t', type: 'numeric', precision: 10, scale: 3, nullable: true })
  maxContainerGrossT?: number | null;

  @OneToMany(() => TrainSetWagon, (wagon) => wagon.wagonType)
  trainSetWagons?: TrainSetWagon[];
}
