import { Column, Entity, JoinColumn, OneToMany, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
import { CompanyEntity } from './company.entity';
import { FactionEntity } from './faction.entity';
import { ImpoundLotParkingEntity } from './impound-lot-parking.entity';
import { PolygonEntity } from './polygon.entity';

@Entity('impound_lots')
export class ImpoundLotEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'int' }) x: number;
    @Column({ type: 'int' }) y: number;
    @Column({ type: 'int' }) z: number;
    @Column({ type: 'varchar', length: 50 }) name: string;
    @Column({ type: 'int', default: null }) company_id: number | null;
    @Column({ type: 'int', default: null }) faction_id: number | null;
    @Column({ type: 'datetime' }) created: Date;
    @Column({ type: 'int' }) created_by: number;
    @Column({ type: 'int', default: null }) pickup_area_x: number | null;
    @Column({ type: 'int', default: null }) pickup_area_y: number | null;
    @Column({ type: 'int', default: null }) pickup_area_z: number | null;
    @Column({ type: 'int', default: null }) pickup_area_h: number | null;

    @Column({ type: 'int', default: null }) terminal_x: number | null;
    @Column({ type: 'int', default: null }) terminal_y: number | null;
    @Column({ type: 'int', default: null }) terminal_z: number | null;
    @Column({ type: 'int', default: null }) terminal_dimension: number | null;

    @Column({ type: 'int', default: null }) polygon_id: number | null;

    @OneToOne(() => CompanyEntity)
    @JoinColumn({
        name: 'company_id',
        referencedColumnName: 'id',
    })
    company?: CompanyEntity;

    @OneToOne(() => FactionEntity)
    @JoinColumn({
        name: 'faction_id',
        referencedColumnName: 'id',
    })
    faction?: FactionEntity;

    @OneToOne(() => PolygonEntity)
    @JoinColumn({
        name: 'polygon_id',
        referencedColumnName: 'id',
    })
    polygon?: PolygonEntity;

    @OneToMany(() => ImpoundLotParkingEntity, (parking) => parking.impound)
    parking?: ImpoundLotParkingEntity[];
}
