import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { PropertyEntity } from './property.entity';
import { InteriorObjectEntity } from './interior-object.entity';

@Entity('interiors')
export class InteriorEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'varchar', length: 50 }) category: string;
    @Column({ type: 'varchar', length: 100 }) name: string;
    @Column({ type: 'float' }) position_x: number;
    @Column({ type: 'float' }) position_y: number;
    @Column({ type: 'float' }) position_z: number;
    @Column() heading: number;

    @Column({ type: 'json' }) ipls: string[] | null;
    @Column({ type: 'json' }) props: string[];
    @Column({ type: 'json' }) emitters: string[];

    @Column({ type: 'int', nullable: true }) freeze: number | null;

    @OneToMany(() => PropertyEntity, (property) => property.interior)
    properties: PropertyEntity[];

    @OneToMany(() => InteriorObjectEntity, (object) => object.interior)
    objects: InteriorObjectEntity[];

    get position(): Vector3 {
        return new mp.Vector3(this.position_x, this.position_y, this.position_z);
    }
}
