import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { ItemTypeEntity } from './item-type.entity';

@Entity('prescriptions')
export class PrescriptionEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'varchar', length: 48, nullable: false }) uuid: string;
    @Column({ type: 'int', nullable: false }) character_id: number;
    @Column({ type: 'varchar', length: 32, nullable: false }) character_name: string;
    @Column({ type: 'int', nullable: false }) drug_item_type_id: number;
    @Column({ type: 'int', nullable: false }) amount: number;
    @Column({ type: 'int', nullable: true }) refill_amount: number | null;
    @Column({ type: 'int', nullable: true }) refill_count: number | null;
    @Column({ type: 'int', nullable: true }) refill_interval: number | null;
    @Column({ type: 'datetime', nullable: true }) last_used: Date | null;
    @Column({ type: 'datetime', nullable: false }) created: Date;
    @Column({ type: 'int' }) prescriber_character_id: number;
    @Column({ type: 'varchar', length: 64 }) prescriber: string;
    @Column({ type: 'varchar', length: 512 }) instructions: string;
    @Column({ type: 'varchar', length: 512 }) record: string;

    @ManyToOne(() => ItemTypeEntity, (itemType) => itemType.prescriptions)
    @JoinColumn({ name: 'drug_item_type_id' })
    itemType: ItemTypeEntity;
}
