"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SalesItem = void 0;
const lodash_1 = __importDefault(require("lodash"));
const dayjs_1 = __importDefault(require("dayjs"));
const column_desciptions_helper_1 = require("../helpers/column-desciptions.helper");
const collaterals_enum_1 = require("../enums/collaterals.enum");
const decimal_js_1 = __importDefault(require("decimal.js"));
class SalesItem {
    bbcDate = null;
    sku = '';
    skuName = '';
    unitsSold = 0;
    unitsCost = 0;
    unitSalePrice = 0;
    salesPeriodStart = null;
    salesPeriodEnd = null;
    salesPerDay = null;
    constructor(item, bbcDate = null, options) {
        if (options && options.salesPeriodStart) {
            item.salesPeriodStart = dayjs_1.default.utc(options.salesPeriodStart).toDate();
        }
        if (options && options.salesPeriodEnd) {
            item.salesPeriodEnd = dayjs_1.default.utc(options.salesPeriodEnd).toDate();
        }
        const salesPeriod = dayjs_1.default.utc(item.salesPeriodEnd).diff(dayjs_1.default.utc(item.salesPeriodStart), 'day') + 1;
        if (typeof item.unitsSold === 'number') {
            this.salesPerDay = (salesPeriod !== 0 && item.unitsSold !== 0)
                ? new decimal_js_1.default(item.unitsSold).div(salesPeriod).toDP(3).toNumber()
                : 0;
        }
        const itemWithDates = (0, column_desciptions_helper_1.convertIntoDates)(item, collaterals_enum_1.ECollaterals.SALES);
        const itemWithoutNulls = lodash_1.default.omitBy(itemWithDates, (value) => value === null);
        Object.assign(this, itemWithoutNulls);
        this.bbcDate = bbcDate;
    }
}
exports.SalesItem = SalesItem;
