import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { ColumnDecimalTransformer } from '../features/utility/ColumnDecimalTransformer';
import { InteriorEntity } from './interior.entity';

@Entity('interior_objects')
export class InteriorObjectEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column() interior_id: number;

    @Column({ type: 'varchar', length: 100 }) hash: string;
    @Column({ type: 'varchar', length: 32, nullable: true }) tag: string | null;
    @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: 'decimal', precision: 17, scale: 12, transformer: new ColumnDecimalTransformer() }) rx: number;
    @Column({ type: 'decimal', precision: 17, scale: 12, transformer: new ColumnDecimalTransformer() }) ry: number;
    @Column({ type: 'decimal', precision: 17, scale: 12, transformer: new ColumnDecimalTransformer() }) rz: number;

    @ManyToOne(() => InteriorEntity, (interior) => interior.objects)
    @JoinColumn({
        name: 'interior_id',
    })
    interior: InteriorEntity;

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

    get rotation(): Vector3 {
        return new mp.Vector3(this.rx, this.ry, this.rz);
    }
}
