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

@Entity('invoice_items')
export class InvoiceItemEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column() invoice_id: number;
    @Column({ type: 'varchar', length: 128 }) name: string;
    @Column() amount: number;
    @Column({ type: 'json' }) unit_price: number | [number, number];
    @Column({ type: 'int' }) sales_tax_category_id: number;
    @Column({ type: 'int' }) sales_tax_percentage: number;
    @Column({ type: 'varchar', width: 128 }) sales_tax_name: string;

    // Relations

    @ManyToOne(() => InvoiceEntity, (invoice) => invoice.items)
    @JoinColumn({ name: 'invoice_id' })
    invoice: InvoiceEntity;
}
