"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalendarRepository = void 0;
const dayjs_1 = __importDefault(require("dayjs"));
const CalandarDay_model_1 = __importDefault(require("../models/CalandarDay.model"));
class CalendarRepository {
    async getNextWorkingDay(date) {
        let nextDay = (0, dayjs_1.default)(new Date(date));
        let isWorking = false;
        do {
            nextDay = nextDay.add(1, 'day');
            const calendarDay = await CalandarDay_model_1.default.findOne({ date: nextDay.format('YYYY-MM-DD') }).lean();
            if (!calendarDay) {
                console.error(`no data in calendar for ${nextDay.format('YYYY-MM-DD')}`);
            }
            isWorking = calendarDay ? calendarDay.workingDay : true;
        } while (isWorking === false);
        return nextDay.format('YYYY-MM-DD');
    }
}
exports.CalendarRepository = CalendarRepository;
