import { Column, Entity, JoinColumn, ManyToOne, OneToMany, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
import { CharacterEntity } from './character.entity';
import { ItemEntity } from './item.entity';
import { PropertyEntity } from './property.entity';
import { WeaponStolenReportEntity } from './weapon-stolen-reports.entity';

@Entity('weapons')
export class WeaponEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'int' }) account_id: number;
    @Column({ type: 'int' }) character_id: number;
    @Column({ type: 'varchar', length: 26 }) character_name: string;
    @Column({ type: 'int' }) item_id: number;
    @Column({ type: 'int' }) item_type_id: number;
    @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP()' }) created: Date;
    @Column({ type: 'tinytext' }) serial: string;
    @Column({ type: 'varchar', length: 60 }) model: string;
    @Column({ type: 'varchar', length: 80 }) purchased_from: string;
    @Column({ type: 'int', nullable: true, default: null }) purchased_property: number | null;

    @Column({ type: 'datetime', default: null, nullable: true }) destroyed: Date | null;
    @Column({ type: 'datetime', default: null, nullable: true }) frees_slot: Date | null;

    @OneToMany(() => WeaponStolenReportEntity, (report) => report.weapon)
    stolenReports?: WeaponStolenReportEntity[];

    @OneToOne(() => ItemEntity)
    @JoinColumn({
        name: 'item_id',
        referencedColumnName: 'id',
    })
    item?: ItemEntity;

    @ManyToOne(() => PropertyEntity)
    @JoinColumn({
        name: 'purchased_property',
        referencedColumnName: 'id',
    })
    property?: PropertyEntity;

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