import { Column, DeleteDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { PropertyPermitTypeEntity } from './property-permit-type.entity';
import { PropertyEntity } from './property.entity';

@Entity('property_permits')
export class PropertyPermitEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'int', nullable: false }) property_id: number;
    @Column({ type: 'int', nullable: false }) permit_type_id: number;
    @Column({ type: 'int', nullable: false }) issued_by_character_id: number;
    @Column({ type: 'int', nullable: false }) issued_by_account_id: number;
    @Column({ type: 'varchar', length: 128, nullable: true }) issued_by: string;
    @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) issued: Date;
    @Column({ type: 'datetime', nullable: true }) suspended: Date | null;
    @DeleteDateColumn({ type: 'datetime', nullable: true }) revoked: Date | null;
    @Column({ type: 'varchar', length: 128, nullable: true }) revoked_by: string | null;

    @ManyToOne(() => PropertyPermitTypeEntity, (permitType) => permitType.permits)
    @JoinColumn({ name: 'permit_type_id' })
    permitType: PropertyPermitTypeEntity;

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