import { Column, Entity, Index, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { TruckingLocationCargoEntity } from './trucking-location-cargo.entity';
import { TruckingTrailerPositionEntity } from './trucking-trailer-position.entity';
import { TruckingLocationLoadingBayEntity } from './trucking-location-loading-bay.entity';
import { TruckingLocationFlatbedBayEntity } from './trucking-location-flatbed-bay.entity';
import { CompanyEntity } from './company.entity';

@Entity('trucking_locations')
export class TruckingLocationEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'varchar', length: 128 }) industry: string;
    @Column({ type: 'varchar', length: 256 }) name: string;
    @Column({ type: 'varchar', length: 256 }) logo_url: string;
    @Column({ type: 'float' }) x: number;
    @Column({ type: 'float' }) y: number;
    @Column({ type: 'float' }) z: number;
    @Index()
    @Column({ type: 'int', nullable: true })
    company_id: number | null;

    @ManyToOne(() => CompanyEntity)
    @JoinColumn({ name: 'company_id' })
    company?: CompanyEntity;

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

    @OneToMany(() => TruckingTrailerPositionEntity, (ttpe) => ttpe.location)
    trailerPositions: TruckingTrailerPositionEntity[];

    @OneToMany(() => TruckingLocationLoadingBayEntity, (tllpe) => tllpe.truckingLocation)
    loadingBays: TruckingLocationLoadingBayEntity[];

    @OneToMany(() => TruckingLocationFlatbedBayEntity, (tllpe) => tllpe.truckingLocation)
    flatbedBays: TruckingLocationFlatbedBayEntity[];
}
