"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InventoryItem = void 0;
const lodash_1 = __importDefault(require("lodash"));
const column_desciptions_helper_1 = require("../helpers/column-desciptions.helper");
const collaterals_enum_1 = require("../enums/collaterals.enum");
class InventoryItem {
    bbcDate = null;
    category = 'NO CATEGORY';
    expiryDate = '';
    location = '';
    lotNumber = 0;
    qty = 1;
    sku = 0;
    skuDate = null;
    skuDescription1 = '';
    skuDescription2 = '';
    skuDescription3 = '';
    detail1 = '';
    detail2 = '';
    detail3 = '';
    unitCost = 0;
    value = 0;
    constructor(item, bbcDate = null, skuDates = []) {
        const itemWithDates = (0, column_desciptions_helper_1.convertIntoDates)(item, collaterals_enum_1.ECollaterals.INVENTORY);
        const itemWithoutNulls = lodash_1.default.omitBy(itemWithDates, (value) => value === null);
        Object.assign(this, itemWithoutNulls);
        this.bbcDate = bbcDate;
        if (!this.skuDate && item.sku) {
            const previousSKUDate = skuDates.find((d) => item.sku.toString().trim() === d._id);
            if (!previousSKUDate) {
                this.skuDate = this.bbcDate;
            }
            else {
                const isPreviousDateGreaterThanSubmittedDate = new Date(previousSKUDate.oldestDate).getTime() > new Date(this.bbcDate).getTime();
                this.skuDate = isPreviousDateGreaterThanSubmittedDate ? this.bbcDate : new Date(previousSKUDate.oldestDate);
            }
        }
    }
}
exports.InventoryItem = InventoryItem;
