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

@Entity('vehicle_keys')
export class VehicleKeyEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'int' }) vehicle_id: number;
    @Column({ type: 'int' }) character_id: number;
    @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP()' }) created: Date;
    @Column({ type: 'int' }) issued_by_character_id: number;
    @Column({ type: 'int', default: 0 }) park: boolean;

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

    @OneToOne(() => CharacterEntity)
    @JoinColumn({
        name: 'character_id',
        referencedColumnName: 'id',
    })
    character?: CharacterEntity;
}
