import { Column, Entity, JoinColumn, ManyToOne, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
import { CharacterEntity } from './character.entity';
import { ImpoundLotEntity } from './impound-lot.entity';
import { VehicleEntity } from './vehicle.entity';

@Entity('vehicle_impound')
export class VehicleImpoundEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'int' }) vehicle_id: number;
    @Column({ type: 'int', nullable: true }) impound_lot: number | null;
    @Column({ type: 'int' }) added_by: number;
    @Column({ type: 'varchar', length: 60 }) added_by_name: string;
    @Column({ type: 'datetime' }) date: Date;
    @Column({ type: 'datetime' }) until: Date;
    @Column({ type: 'varchar', length: 256 }) reason: string;
    @Column({ type: 'datetime', default: null }) collected: Date | null;
    @Column({ type: 'int', default: null }) collected_by: number | null;
    @Column({ type: 'int', default: null }) payment: number | null;

    @OneToOne(() => VehicleEntity)
    @JoinColumn({
        name: 'vehicle_id',
        referencedColumnName: 'id',
    })
    vehicle: VehicleEntity;

    @ManyToOne(() => CharacterEntity)
    @JoinColumn({
        name: 'added_by',
        referencedColumnName: 'id',
    })
    added?: CharacterEntity;

    @ManyToOne(() => CharacterEntity)
    @JoinColumn({
        name: 'collected_by',
        referencedColumnName: 'id',
    })
    collecter?: CharacterEntity;

    @ManyToOne(() => ImpoundLotEntity)
    @JoinColumn({
        name: 'impound_lot',
        referencedColumnName: 'id',
    })
    impound?: ImpoundLotEntity;
}
