"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setManualInputsToggle = exports.updateAvailabilityStatus = exports.saveInventoryAvailabilitySummary = exports.saveInventoryAvailabilityItems = exports.getInventoryAvailabilityByBBCDateId = void 0;
const InventoryAvailability_model_1 = require("../models/InventoryAvailability.model");
const InventoryAvailabilityItem_model_1 = require("../models/InventoryAvailabilityItem.model");
const getInventoryAvailabilityByBBCDateId = async (bbcDateId) => {
    return InventoryAvailability_model_1.InventoryAvailabilityModel
        .findOne({ bbcDateId })
        .lean();
};
exports.getInventoryAvailabilityByBBCDateId = getInventoryAvailabilityByBBCDateId;
const saveInventoryAvailabilityItems = async (inventoryAvailabilityId, items) => {
    await InventoryAvailabilityItem_model_1.InventoryAvailabilityItemModel.deleteMany({ inventoryAvailabilityId });
    await InventoryAvailabilityItem_model_1.InventoryAvailabilityItemModel.insertMany(items);
};
exports.saveInventoryAvailabilityItems = saveInventoryAvailabilityItems;
const saveInventoryAvailabilitySummary = async (inventoryAvailabilityId, summary) => {
    await InventoryAvailability_model_1.InventoryAvailabilityModel.findByIdAndUpdate(inventoryAvailabilityId, { summary }, { upsert: true, new: true });
};
exports.saveInventoryAvailabilitySummary = saveInventoryAvailabilitySummary;
const updateAvailabilityStatus = async (bbcDateId, status) => {
    await InventoryAvailability_model_1.InventoryAvailabilityModel.updateOne({ bbcDateId }, { status });
};
exports.updateAvailabilityStatus = updateAvailabilityStatus;
const setManualInputsToggle = async (bbcDateId, useManualInputs) => {
    await InventoryAvailability_model_1.InventoryAvailabilityModel.updateOne({ bbcDateId }, { useManualInputs });
};
exports.setManualInputsToggle = setManualInputsToggle;
