import { TerminalProviders } from "./Terminal";
export var TerminalOrderType;
(function (TerminalOrderType) {
    TerminalOrderType["boardingOnly"] = "boarding_only";
    TerminalOrderType["boardingShipping"] = "boarding_shipping";
})(TerminalOrderType || (TerminalOrderType = {}));
export var TerminalOrderStatus;
(function (TerminalOrderStatus) {
    TerminalOrderStatus["created"] = "created";
    TerminalOrderStatus["submitted"] = "submitted";
    TerminalOrderStatus["completed"] = "completed";
    TerminalOrderStatus["in_progress"] = "in_progress";
    TerminalOrderStatus["on_hold"] = "on_hold";
    TerminalOrderStatus["canceled"] = "canceled";
})(TerminalOrderStatus || (TerminalOrderStatus = {}));
export class TerminalOrder {
    constructor(data) {
        this.id = data.id;
        this.business_id = data.business_id;
        this.company_name = data.company_name;
        this.sub_account_id = data.sub_account_id;
        this.provider = data.provider || TerminalProviders.verifone;
        this.order_items = [];
        this.order_type = data.order_type;
        this.order_status = data.order_status;
        this.terminals = data.terminals;
        this.created_at = data.created_at;
        this.updated_at = data.updated_at;
    }
    get payload() {
        return {
            business_id: this.business_id,
            sub_account_id: this.sub_account_id,
            order_type: this.order_type,
            order_items: this.order_items,
        };
    }
    get totalQuantity() {
        return this.order_items.reduce((acc, item) => acc + item.quantity, 0);
    }
    updateTerminal(model_name, quantity) {
        // if quantity is 0, remove terminal
        if (quantity === 0) {
            this.order_items = this.order_items.filter((t) => t.model_name !== model_name);
            return;
        }
        const terminal = this.order_items.find((t) => t.model_name === model_name);
        if (terminal) {
            terminal.quantity = quantity;
        }
        else {
            this.order_items.push({ model_name, quantity });
        }
    }
}
