import { Model } from 'front';
import { padMoney } from '../../etc/format';

/**\

    title: ManifestItem
    category: model
    description:
        A pretty sweet model representing a line
        item of an order manifest

\**/
class ManifestItem extends Model {
    constructor(data) {
        super({
            description: '',
            qty: null,
            price: null
        });

        this.fill(data);
    }

    total() {
        if (this.qty === null || this.price === null) {
            return null;
        }

        return this.qty * this.price;
    }

    asLine() {
        let out = '';

        if (this.qty) {
            out = this.qty + ' x ';
        }

        out += this.description;

        if (this.price) {
            out += ' @ $' + padMoney(this.price);
        }

        return out;
    }
}

export default ManifestItem;
