import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { PropertyEntity } from './property.entity';

@Entity('doors')
export class DoorEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'varchar', length: 10, nullable: false }) type: string;
    @Column({ type: 'varchar', length: 100, nullable: false }) name: string;
    @Column({ type: 'bigint', nullable: false }) model: string;
    @Column({ type: 'int', nullable: false }) x: number;
    @Column({ type: 'int', nullable: false }) y: number;
    @Column({ type: 'int', nullable: false }) z: number;
    @Column({ type: 'int', nullable: true }) x2: number | null;
    @Column({ type: 'int', nullable: true }) y2: number | null;
    @Column({ type: 'int', nullable: true }) z2: number | null;
    @Column({ type: 'int', nullable: true, default: null }) property_id: number | null;
    @Column({ type: 'varchar', length: 100, nullable: true, default: null }) permission_name: string | null;
    @Column({ type: 'varchar', length: 15, nullable: false, default: 'LOCK_ON_START' }) lock_type: DoorLockTypes;
    @Column({ type: 'int', default: 0 }) lock_status: number;
    @Column({ type: 'int', nullable: true }) dimension: number | null;
    @Column({ type: 'json', nullable: true, default: null }) linked_doors: number[] | null;

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

    locked: boolean;
    processingState = false;
}

export enum DoorLockTypes {
    LOCK_ON_START = 'LOCK_ON_START',
    OPEN_ON_START = 'OPEN_ON_START',
    ALWAYS_LOCKED = 'ALWAYS_LOCKED',
    ALWAYS_OPEN = 'ALWAYS_OPEN',
    USE_LAST_SET = 'USE_LAST_SET',
}
