import { Column, Entity, JoinTable, ManyToMany, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { TruckingLocationCargoEntity } from './trucking-location-cargo.entity';
import { TruckingContainerEntity } from './trucking-container.entity';

@Entity('trucking_cargo')
export class TruckingCargoEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'varchar', length: 128 }) name: string;
    @Column({ type: 'varchar', length: 32 }) unit: string;
    @Column() unit_weight: number;
    @Column() unit_volume: number;
    @Column({ type: 'varchar', length: 64, nullable: true }) special: string | null;
    @Column({ type: 'json', nullable: true }) icons:
        | null
        | {
              bgColor: string;
              name: string;
          }[];
    @Column({ type: 'int', default: 1 }) pay_modifier: number;

    @OneToMany(() => TruckingLocationCargoEntity, (tlce) => tlce.location)
    locationCargo: TruckingLocationCargoEntity[];

    @ManyToMany(() => TruckingContainerEntity)
    @JoinTable({
        name: 'trucking_cargo_containers',
        joinColumn: { name: 'trucking_cargo_id' },
        inverseJoinColumn: { name: 'trucking_container_id' },
    })
    containers: TruckingContainerEntity[];
}
