"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MonthEndDataService = void 0;
const MonthEndData_Model_1 = require("../models/MonthEndData.Model");
class MonthEndDataService {
    async upsertMonthEndData(input) {
        const { productId, year, month, dataType, dataValue } = input;
        if (!Object.values(MonthEndData_Model_1.EMonthEndDataType).includes(input.dataType)) {
            throw new Error(`Invalid dataType: ${dataType}`);
        }
        return MonthEndData_Model_1.MonthEndData.findOneAndUpdate({
            productId,
            year,
            month,
            dataType,
        }, {
            $set: {
                dataValue,
            },
        }, {
            upsert: true,
            new: true,
            setDefaultsOnInsert: true,
        });
    }
    async getMonthEndData(productId, year, month) {
        return MonthEndData_Model_1.MonthEndData.find({ productId, year, month });
    }
}
exports.MonthEndDataService = MonthEndDataService;
