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

@Entity('vehicle_insurance')
export class VehicleInsuranceEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'int' }) vehicle_id: number;
    @Column({ type: 'int', nullable: true }) character_id: number | null;
    @Column({ type: 'int', nullable: true }) company_id: number | null;
    @Column({ type: 'varchar', length: 16 }) phone_number: string;
    @Column({ type: 'int', default: 250 }) fee: number;
    @Column({ type: 'int', default: 0 }) debt: number;
    @Column({ type: 'datetime' }) created_on: Date;
    @Column({ type: 'datetime' }) last_payment: Date;

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

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

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