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

@Entity('weapon_licenses')
export class WeaponLicenseEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'int', unique: true, nullable: false }) character_id: number;
    @Column({ type: 'varchar', nullable: false }) character_name: string;
    @Column({ type: 'tinyint', default: 0 }) is_ccw: boolean;
    @Column({ type: 'tinyint', default: 0 }) is_guard: boolean;
    @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) created: Date;
    @Column({ type: 'datetime' }) expires: Date;
    @Column({ type: 'int' }) issued_by: number;
    @Column({ type: 'int' }) issued_by_character_id: number;
    @Column({ type: 'varchar' }) issued_by_character_name: string;

    @Column({ type: 'datetime', nullable: true, default: null }) revoked: Date | null;
    @Column({ type: 'int', default: null, nullable: true }) revoked_by: number | null;
    @Column({ type: 'int', default: null, nullable: true }) revoked_by_character_id: number | null;
    @Column({ type: 'varchar', default: null, nullable: true }) revoked_by_character_name: string | null;

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

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

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