import { Column, Entity, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { DarknetOrderItemEntity } from './darknet-order-item.entity';
import { PropertyEntity } from './property.entity';
import { InventoryEntity } from './inventory.entity';

@Entity('darknet_orders')
export class DarknetOrderEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column() character_id: number;
    @Column() property_id: number;
    @Column() inventory_id: number;
    @Column() delivery_attempts: number;
    @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) created: Date;
    @Column({ type: 'datetime', nullable: true }) delivered: Date | null;
    @Column({ type: 'datetime' }) deliver_after: Date;

    @OneToMany(() => DarknetOrderItemEntity, (item) => item.order)
    items: DarknetOrderItemEntity[];

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

    @ManyToOne(() => InventoryEntity, (inventory) => inventory.darknetOrders)
    @JoinColumn({ name: 'inventory_id' })
    inventory: InventoryEntity;
}
