"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BorrowerCompliance = exports.BorrowerComplianceSchema = void 0;
const mongoose_1 = __importDefault(require("mongoose"));
const _models_1 = require("./_models");
const BorrowerComplianceInstanceSchema = new mongoose_1.default.Schema({
    nextDate: {
        type: Date,
        required: false,
    },
    submittedDate: {
        type: Date,
        required: false,
    },
    status: {
        type: String,
        trim: true,
        required: false,
    },
    files: [{
            fileId: {
                type: String,
                trim: true,
                required: true,
            },
            name: {
                type: String,
                trim: true,
                required: true,
            },
            isFileNew: {
                type: Boolean,
                required: false,
                default: true,
            },
            uploadedAt: {
                type: Date,
                required: false,
            },
            uploadedBy: {
                type: String,
                required: false,
            },
        }],
}, { timestamps: true });
const BorrowerComplianceItemSchema = new mongoose_1.default.Schema({
    item: {
        type: mongoose_1.default.Schema.Types.ObjectId,
        ref: _models_1.MODEL_NAMES.complianceItems,
        required: false,
    },
    startDate: {
        type: Date,
        required: false,
    },
    frequency: {
        type: String,
        trim: true,
        required: false,
    },
    emailAddresses: [{
            email: {
                type: String,
                trim: true,
                required: false,
            },
            title: {
                type: String,
                trim: true,
                required: false,
            },
            isActive: {
                type: Boolean,
                required: false,
            },
        }],
    instances: [BorrowerComplianceInstanceSchema],
}, { timestamps: true });
exports.BorrowerComplianceSchema = new mongoose_1.default.Schema({
    isVisible: {
        type: Boolean,
    },
    borrower: {
        type: mongoose_1.default.Schema.Types.ObjectId,
        ref: _models_1.MODEL_NAMES.borrowers,
        required: true,
    },
    complianceNotes: [{
            note: {
                type: String,
                trim: true,
                required: true,
            },
            date: {
                type: Date,
                required: true,
            },
            user: {
                type: String,
                trim: true,
                required: false,
            },
        }],
    borrowerNotes: [{
            note: {
                type: String,
                trim: true,
                required: true,
            },
            date: {
                type: Date,
                required: true,
            },
            user: {
                type: String,
                trim: true,
                required: false,
            },
        }],
    email: {
        type: String,
        trim: true,
        required: false,
    },
    mainEmails: [{
            email: {
                type: String,
                trim: true,
                required: false,
            },
            title: {
                type: String,
                trim: true,
                required: false,
            },
            isActive: {
                type: Boolean,
                required: false,
            },
        }],
    financialEmails: [{
            email: {
                type: String,
                trim: true,
                required: false,
            },
            title: {
                type: String,
                trim: true,
                required: false,
            },
            isActive: {
                type: Boolean,
                required: false,
            },
        }],
    isEmailingActive: {
        type: Boolean,
        required: false,
        default: false,
    },
    isDailyTransactionsEmailingActive: {
        type: Boolean,
        required: false,
        default: false,
    },
    plaidAccessToken: {
        type: String,
        trim: true,
        required: false,
        select: false,
    },
    fundingStatus: {
        type: String,
        trim: true,
        required: false,
    },
    lastEmailSentAt: {
        type: Date,
        required: false,
    },
    items: [BorrowerComplianceItemSchema],
    __v: { type: Number, select: false },
}, { timestamps: true });
exports.BorrowerCompliance = mongoose_1.default.model(_models_1.MODEL_NAMES.complianceBorrowers, exports.BorrowerComplianceSchema);
