"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LockService = void 0;
const AvailabilitySigns_model_1 = require("../models/AvailabilitySigns.model");
class LockService {
    collateralsService;
    constructor(collateralsService) {
        this.collateralsService = collateralsService;
    }
    async isDateLocked(checkDate, borrowerId) {
        const bbcDocsAfter = await this.collateralsService.gebNextBBC(borrowerId, checkDate);
        const activeSignsAfter = await AvailabilitySigns_model_1.AvailabilitySignsModel.aggregate([
            {
                $match: {
                    'bbcDateId': { $in: bbcDocsAfter.map((bbc) => bbc._id) },
                },
            }, {
                $unwind: {
                    path: '$signs',
                    preserveNullAndEmptyArrays: true,
                },
            }, {
                $match: {
                    'signs.revokedAt': {
                        $exists: false,
                    },
                },
            }, {
                $group: {
                    '_id': '$_id',
                    'requiredSigns': { $first: '$requiredSigns' },
                    'signs': { $push: '$signs' },
                },
            }, {
                $match: {
                    $expr: {
                        $gte: [{ '$size': '$signs' }, '$requiredSigns'],
                    },
                },
            },
        ]);
        return activeSignsAfter.length > 0;
    }
}
exports.LockService = LockService;
