import { model, property } from '@loopback/repository';
import { getJsonSchema } from '@loopback/rest';

import { AmountUnit } from './amount-unit.model';
import { Vat } from './vat.model';

/**
 * Contains information about a single item of an invoice.
 */
@model()
export class InvoiceItem {
    /**
     * The name of the item.
     */
    @property({
        type: 'string',
        required: true
    })
    name: string;
    /**
     * The amount of the item.
     */
    @property({
        type: 'number',
        required: true
    })
    amount: number;
    /**
     * The unit, eg. Pieces or meter.
     * Is either a free string or an object containing a display name and a code.
     * (This is required for factur-x/x-rechnung conformance).
     */
    @property({
        type: 'object',
        required: true,
        jsonSchema: getJsonSchema(AmountUnit)
    })
    amountUnit: AmountUnit;
    /**
     * The tax on the item.
     * Is either a percentage number (eg. 20 means 20%) or an object containing a percentage number and a code.
     * (This is required for factur-x/x-rechnung conformance).
     */
    @property({
        type: 'object',
        required: true,
        jsonSchema: getJsonSchema(Vat)
    })
    vat: Vat;
    /**
     * The price of the item.
     */
    @property({
        type: 'number',
        required: true
    })
    price: number;
}