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

@Entity('property_security')
export class PropertySecurityEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'varchar', length: 100 }) name: string;
    @Column({ type: 'int', nullable: true }) type: number | null;
    @Column({ type: 'int', nullable: true }) level: number | null;
    @Column({ type: 'tinyint', default: false }) enabled: boolean;
    @Column({ type: 'tinyint', default: false }) installed: boolean;
    @Column({ type: 'int', nullable: true }) property_id: number | null;
    @Column({ type: 'int', nullable: true }) fee: number | null;
    @Column({ type: 'int', nullable: true }) debt: number | null;

    @Column({ type: 'varchar', length: 100 }) hash: string;
    @Column() dimension: number;
    @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;

    @Column({ type: 'int', nullable: true }) contract_id: number | null;
    @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) created: Date;
    @Column({ type: 'varchar', length: 128 }) created_by: string;
    @Column({ type: 'int', nullable: true }) company_id: number | null;

    @ManyToOne(() => PropertyEntity, (type) => type.securitySystem)
    @JoinColumn({ name: 'property_id' })
    property: PropertyEntity;

    object?: ObjectMp;
    alarm_timeout?: NodeJS.Timeout;
}
