"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PostponedTransactionsService = void 0;
const mongoose_1 = __importDefault(require("mongoose"));
const dayjs_1 = __importDefault(require("dayjs"));
class PostponedTransactionsService {
    calendarService;
    postponedTransactionsRepository;
    constructor(calendarService, postponedTransactionsRepository) {
        this.calendarService = calendarService;
        this.postponedTransactionsRepository = postponedTransactionsRepository;
    }
    async cleanRecalculated(transactionId) {
        await this.postponedTransactionsRepository.cleanRecalculated(transactionId);
    }
    async createPostponedTransaction(transaction) {
        const currentDay = (0, dayjs_1.default)(new Date(transaction.date)).format('YYYY-MM-DD');
        const workingDate = await this.calendarService.getNextWorkingDay(currentDay);
        const postponedTransaction = {
            postponedToDate: workingDate,
            transactionId: new mongoose_1.default.Types.ObjectId(String(transaction._id)),
            productId: new mongoose_1.default.Types.ObjectId(String(transaction.productId)),
        };
        await this.postponedTransactionsRepository.createPostponedTransaction(postponedTransaction);
    }
}
exports.PostponedTransactionsService = PostponedTransactionsService;
