import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { ColumnDecimalTransformer } from '../features/utility/ColumnDecimalTransformer';
import { InventoryEntity } from './inventory.entity';

@Entity('corpses')
export class CorpseEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'int' }) character_id: number;
    @Column({ type: 'json' }) appearance: PedCustomization;
    @Column({ type: 'json' }) damages: DamageHistory[];
    @Column({ type: 'varchar', length: 32 }) model: string;
    @Column({ type: 'decimal', precision: 17, scale: 12, transformer: new ColumnDecimalTransformer() }) x: number;
    @Column({ type: 'decimal', precision: 17, scale: 12, transformer: new ColumnDecimalTransformer() }) y: number;
    @Column({ type: 'decimal', precision: 17, scale: 12, transformer: new ColumnDecimalTransformer() }) z: number;
    @Column({ type: 'int', nullable: false }) dimension: number;
    @Column({ type: 'boolean', default: false }) at_morgue: boolean;
    @Column({ type: 'boolean', default: false }) identified: boolean;
    @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP()' }) created: Date;
    @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP()' }) last_interaction: Date;
    @Column({ type: 'datetime', nullable: true, default: null }) stored: Date | null;
    @Column({ type: 'datetime', nullable: true, default: null }) requested_id: Date | null;
    @Column({ type: 'boolean', default: false }) buried: boolean;
    @Column({ type: 'datetime', nullable: true, default: null }) buried_date: Date | null;

    inventory?: InventoryEntity;
    spawned = false;
    in_vehicle?: number | undefined;
    being_buried = false;

    get position(): Vector3 {
        return new mp.Vector3(this.x, this.y, this.z);
    }
}
