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

@Entity('drivers_licenses')
export class DriversLicenseEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'int', nullable: false }) character_id: number;
    @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) issued: Date;
    @Column({ type: 'datetime', nullable: false }) expires: Date;
    @Column({ type: 'int', default: 0 }) warnings: number;
    @Column({ type: 'datetime', default: null, nullable: true }) last_warning: Date | null;
    @Column({ type: 'datetime', nullable: true, default: null }) suspended_until: Date | null;
    @Column({ type: 'int', nullable: true, default: null }) suspended_by: number | null;
    @Column({ type: 'int', nullable: true, default: null }) suspended_by_character_id: number | null;
    @Column({ type: 'datetime', default: null, nullable: true }) suspended_on: Date | null;
    @Column({ type: 'varchar', length: 3 }) class: string;
    @Column({ type: 'tinyint', default: 0 }) is_permit: boolean;
    @Column({ type: 'datetime', nullable: true, default: null }) revoked: Date | null;
    @Column({ type: 'int', nullable: true, default: null }) revoked_by: number | null;
    @Column({ type: 'int', nullable: true, default: null }) revoked_by_character_id: number | null;
    @Column({ type: 'varchar', nullable: true, default: null }) revoked_by_character_name: string | null;

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

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

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