"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PurchaseOrder = exports.ProductPurchase = exports.PurchaseOrderCost = exports.PurchaseOrderStatus = exports.ShippingMethod = exports.PurchaseOrderExpenseType = exports.PurchaseOrderStatusType = void 0;
const jackson_js_1 = require("jackson-js");
const lodash_1 = __importDefault(require("lodash"));
var PurchaseOrderStatusType;
(function (PurchaseOrderStatusType) {
    PurchaseOrderStatusType["DRAFT"] = "DRAFT";
    PurchaseOrderStatusType["WORKING"] = "WORKING";
    PurchaseOrderStatusType["SHIPPING"] = "SHIPPING";
    PurchaseOrderStatusType["COMPLETED"] = "COMPLETED";
})(PurchaseOrderStatusType = exports.PurchaseOrderStatusType || (exports.PurchaseOrderStatusType = {}));
var PurchaseOrderExpenseType;
(function (PurchaseOrderExpenseType) {
    PurchaseOrderExpenseType["PRODUCTION"] = "PRODUCTION";
    PurchaseOrderExpenseType["DUTY"] = "DUTY";
    PurchaseOrderExpenseType["SHIPPING"] = "SHIPPING";
    PurchaseOrderExpenseType["TAX"] = "TAX";
    PurchaseOrderExpenseType["EXTRA"] = "EXTRA";
})(PurchaseOrderExpenseType = exports.PurchaseOrderExpenseType || (exports.PurchaseOrderExpenseType = {}));
var ShippingMethod;
(function (ShippingMethod) {
    ShippingMethod["TRUCK"] = "TRUCK";
    ShippingMethod["SHIP"] = "SHIP";
    ShippingMethod["TRAIN"] = "TRAIN";
    ShippingMethod["PLANE"] = "PLANE";
})(ShippingMethod = exports.ShippingMethod || (exports.ShippingMethod = {}));
class PurchaseOrderStatus {
}
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [String] })
], PurchaseOrderStatus.prototype, "status", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [Date] })
], PurchaseOrderStatus.prototype, "date", void 0);
exports.PurchaseOrderStatus = PurchaseOrderStatus;
class PurchaseOrderCost {
}
__decorate([
    (0, jackson_js_1.JsonProperty)()
], PurchaseOrderCost.prototype, "reference", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [String] })
], PurchaseOrderCost.prototype, "type", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], PurchaseOrderCost.prototype, "transactionId", void 0);
exports.PurchaseOrderCost = PurchaseOrderCost;
class ProductPurchase {
}
__decorate([
    (0, jackson_js_1.JsonProperty)()
], ProductPurchase.prototype, "id", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], ProductPurchase.prototype, "bin", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], ProductPurchase.prototype, "quantity", void 0);
exports.ProductPurchase = ProductPurchase;
class PurchaseOrder {
    constructor() {
        this.productPurchases = [];
        this.statusHistory = [];
        this.costs = [];
    }
    getProductPurchaseQuantityBySku(bins) {
        const totalQuantity = lodash_1.default.reduce(this.productPurchases, (acc, i) => {
            if (lodash_1.default.includes(bins, i.bin)) {
                return acc + i.quantity;
            }
            return acc;
        }, 0);
        return totalQuantity;
    }
    getPurchasedBins() {
        return lodash_1.default.map(this.productPurchases, p => (p.bin));
    }
    getProductPurchaseBySku(bin) {
        return lodash_1.default.find(this.productPurchases, (p) => (p.bin == bin));
    }
}
__decorate([
    (0, jackson_js_1.JsonProperty)()
], PurchaseOrder.prototype, "id", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], PurchaseOrder.prototype, "name", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], PurchaseOrder.prototype, "notes", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [String] })
], PurchaseOrder.prototype, "vectorType", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [String] })
], PurchaseOrder.prototype, "status", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [Array, [ProductPurchase]] })
], PurchaseOrder.prototype, "productPurchases", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [Array, [PurchaseOrderStatus]] })
], PurchaseOrder.prototype, "statusHistory", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [Array, [PurchaseOrderCost]] })
], PurchaseOrder.prototype, "costs", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)({ required: false }),
    (0, jackson_js_1.JsonClassType)({ type: () => [Date] })
], PurchaseOrder.prototype, "availableAt", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [Date] })
], PurchaseOrder.prototype, "createdAt", void 0);
exports.PurchaseOrder = PurchaseOrder;
//# sourceMappingURL=purchase_order.js.map