"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Prospect = exports.ProspectSchema = exports.ProspectValidationSchema = exports.ProspectInfoValidationSchema = exports.ProspectInfoExternalValidationSchema = exports.baseFields = exports.externalProspectInitialInfo = exports.initialFileGroups = exports.NO_ROW_ID = exports.prospectFileGroupsMap = exports.prospectFileGroups = exports.EProspectFileGroups = exports.EProspectDeclineReason = exports.EProspectStatusDict = exports.EProspectStatus = exports.EProspectPriority = exports.sharepointFoldersDictionary = exports.prospectFieldsDictionary = void 0;
const mongoose_1 = __importDefault(require("mongoose"));
const joi_1 = __importDefault(require("joi"));
const _models_1 = require("./_models");
const ProspectInfoStageTwo_model_1 = require("./ProspectInfoStageTwo.model");
const ProspectInfoStageOne_model_1 = require("./ProspectInfoStageOne.model");
const main_helper_1 = require("../helpers/main.helper");
const ProspectInfoNote_model_1 = require("./ProspectInfoNote.model");
const textFieldMaxLength = 600;
exports.prospectFieldsDictionary = {
    name: 'Name',
    industry: 'Industry',
    status: 'Status',
    probability: 'Probability',
    revolverAmount: 'Revolver Amount',
    termAmount: 'Term Amount',
    keyDates: {
        lastContact: 'Last Contact',
        receivedDate: 'Received Date',
        LOISubmitted: 'LOI Submitted',
        DDStarted: 'DD Started',
        expectedFunding: 'Expected Funding',
        dropDate: 'Drop Date',
    },
    priority: 'Priority',
    declineReason: 'Decline Reason',
    sourceId: 'Source',
    collaterals: {
        equipment: 'Equipment',
        inventory: 'Inventory',
        receivables: 'Receivables',
        other: 'Other',
    },
    closingPoints: 'Closing Points',
    comments: 'Comments',
};
exports.sharepointFoldersDictionary = {
    confidential: 'Confidential - Personal Information',
    confidentialDeclined: 'Declined',
    // TOP
    legal: 'Legal',
    portfolio: 'Portfolio',
    underwriting: 'Underwriting',
    // > Legal
    drafts: 'Drafts',
    finalDocuments: 'Final Documents',
    // > Portfolio
    APReports: '01. AP Reports',
    ARReports: '02. AR Reports',
    borrowingBaseCertificatesAndBackup: '03. Borrowing Base Certificates and Backup',
    financials: '04. Financials',
    inventory: '05. Inventory',
    machineryEquipment: '06. Machinery & Equipment',
    taxes: '07. Taxes',
    insurance: '08. Insurance',
    fieldExams: '09. Field Exams',
    payments: '10. Payments',
    interestStatements: '11. Interest Statements',
    leasesRealEstate: '12. Leases & Real Estate',
    agreementsContracts: '13. Agreements & Contracts',
    liensLitigation: '14. Liens & Litigation',
    verifications: '15. Verifications',
    onlineBankingInstructions: '16. Online Banking Instructions',
    compliance: '17. Compliance',
    portfolio_other: '18. Other',
    // > Underwriting
    dueDiligence: '01. Due Diligence',
    loi: '02. LOI',
    loanMemoApprovals: '03. Loan Memo & Approvals',
    // > Underwriting > 02. LOI
    loiTemplates: 'zz Templates',
    // > Underwriting > 03. Loan Memo & Approvals
    loanMemo: '01. Loan Memo',
    dataTablesWorkings: '02. Data, Tables & Workings',
    approvalEmails: '03. Approval Emails',
    templatesSamples: 'zz Templates and Samples',
    // > Underwriting > 01. Due Diligence
    corporateDocuments: '01. Corporate Documents',
    // > Underwriting > 01. Due Diligence > 01. Corporate Documents
    organizationDocumentsGoodStandings: 'a. Organization Documents and Good Standings',
    disclosureSchedule: 'b. Disclosure Schedule',
    corporateDocuments_insurance: 'c. Insurance',
    ownership: 'd. Ownership',
    officersManagersStaff: 'e. Officers, Managers, Staff',
    // > Underwriting > 01. Due Diligence
    lienLitigationSearchesTaxes: '02. Lien & Litigation Searches and Taxes',
    // > Underwriting > 01. Due Diligence > 02. Lien & Litigation Searches and Taxes
    lienLitigationSearch: 'a. Lien & Litigation Search',
    disclosedLitigations: 'b. Disclosed Litigations',
    payrollTaxStatementsProofOfPayment: 'c. Payroll Tax Statements & Proof of Payment',
    incomeTaxReturns: 'd. Income Tax Returns',
    personalPropertyTaxStatementsProofOfPayment: 'e. Personal Property Tax Statements and Proof of Payment',
    // > Underwriting > 01. Due Diligence
    KYC: '03. KYC',
    // > Underwriting > 01. Due Diligence
    collateral: '04. Collateral',
    // > Underwriting > 01. Due Diligence > 04. Collateral
    collateral_inventory: 'a. Inventory',
    receivables: 'b. Receivables',
    equipment: 'c. Equipment',
    fieldExamAppraisals: 'd. Field Exam & Appraisals',
    borrowingBases: 'e. Borrowing Bases',
    // > Underwriting > 01. Due Diligence
    financialsBankStatements: '05. Financials and Bank Statements',
    // > Underwriting > 01. Due Diligence > 05. Financials and Bank Statements
    historicalFinancials: 'a. Historical Financials',
    projections: 'b. Projections',
    bankStatements: 'c. Bank Statements',
    accountsPayables: 'd. Accounts Payables',
    currentDebt: 'e. Current Debt',
    // > Underwriting > 01. Due Diligence
    majorContracts: '06. Major Contracts',
    // > Underwriting > 01. Due Diligence > 06. Major Contracts
    leases: 'a. Leases',
    it: 'b. IT',
    majorContracts_other: 'c. Other',
    // > Underwriting > 01. Due Diligence
    intellectualProperty: '07. Intellectual Property',
    // > Underwriting > 01. Due Diligence
    fieldExamRequests: '08. Field Exam Requests',
    // > Underwriting > 01. Due Diligence
    customerVendorLists: '09. Customer & Vendor Lists',
    // > Underwriting > 01. Due Diligence
    other: '10. Other',
    // > Underwriting > 01. Due Diligence
    standardEmailAttachments: 'zz Standard Email Attachments',
    underwriting_templates: 'zz Templates',
};
var EProspectPriority;
(function (EProspectPriority) {
    EProspectPriority["LOW"] = "LOW";
    EProspectPriority["MEDIUM"] = "MEDIUM";
    EProspectPriority["HIGH"] = "HIGH";
})(EProspectPriority || (exports.EProspectPriority = EProspectPriority = {}));
var EProspectStatus;
(function (EProspectStatus) {
    EProspectStatus["PROSPECT"] = "PROSPECT";
    EProspectStatus["TERM_SHEET"] = "TERM_SHEET";
    EProspectStatus["DUE_DILIGENCE"] = "DUE_DILIGENCE";
    EProspectStatus["PHASE_2"] = "PHASE_2";
    EProspectStatus["LOAN_DOCUMENTS"] = "LOAN_DOCUMENTS";
    EProspectStatus["FUNDED"] = "FUNDED";
})(EProspectStatus || (exports.EProspectStatus = EProspectStatus = {}));
var EProspectStatusDict;
(function (EProspectStatusDict) {
    EProspectStatusDict["PROSPECT"] = "Prospect";
    EProspectStatusDict["TERM_SHEET"] = "Term Sheet";
    EProspectStatusDict["DUE_DILIGENCE"] = "Due Diligence";
    EProspectStatusDict["PHASE_2"] = "Phase II";
    EProspectStatusDict["LOAN_DOCUMENTS"] = "Loan Documents";
    EProspectStatusDict["FUNDED"] = "Funded";
})(EProspectStatusDict || (exports.EProspectStatusDict = EProspectStatusDict = {}));
var EProspectDeclineReason;
(function (EProspectDeclineReason) {
    EProspectDeclineReason["NOT_DECLINED"] = "NOT_DECLINED";
    EProspectDeclineReason["DO_NOT_LIKE_COLLATERAL"] = "DO_NOT_LIKE_COLLATERAL";
    EProspectDeclineReason["INSUFFICIENT_COLLATERAL"] = "INSUFFICIENT_COLLATERAL";
    EProspectDeclineReason["LOST_TO_COMPETITOR"] = "LOST_TO_COMPETITOR";
    EProspectDeclineReason["DOES_NOT_FIT_LENDING_CRITERIA"] = "DOES_NOT_FIT_LENDING_CRITERIA";
    EProspectDeclineReason["DATA_QUALITY"] = "DATA_QUALITY";
    EProspectDeclineReason["DID_NOT_HEAR_BACK"] = "DID_NOT_HEAR_BACK";
    EProspectDeclineReason["NOT_ENOUGH_CAPITAL_TO_FUND"] = "NOT_ENOUGH_CAPITAL_TO_FUND";
})(EProspectDeclineReason || (exports.EProspectDeclineReason = EProspectDeclineReason = {}));
var EProspectFileGroups;
(function (EProspectFileGroups) {
    EProspectFileGroups["borrowingBase"] = "borrowingBase";
    EProspectFileGroups["corporateDocuments"] = "corporateDocuments";
    EProspectFileGroups["ownershipStructure"] = "ownershipStructure";
    EProspectFileGroups["organizationStructure"] = "organizationStructure";
    EProspectFileGroups["financialsBankInformation"] = "financialsBankInformation";
    EProspectFileGroups["financialsBankInformation_historicalFinancials"] = "financialsBankInformation_historicalFinancials";
    EProspectFileGroups["financialsBankInformation_projections"] = "financialsBankInformation_projections";
    EProspectFileGroups["financialsBankInformation_bankStatements"] = "financialsBankInformation_bankStatements";
    EProspectFileGroups["historicalFinancials"] = "historicalFinancials";
    EProspectFileGroups["projections"] = "projections";
    EProspectFileGroups["accountsPayables"] = "accountsPayables";
    EProspectFileGroups["collateralSales"] = "collateralSales";
    EProspectFileGroups["receivables"] = "receivables";
    EProspectFileGroups["taxes"] = "taxes";
    EProspectFileGroups["taxesIncome"] = "taxesIncome";
    EProspectFileGroups["taxesProperty"] = "taxesProperty";
    EProspectFileGroups["taxesPayroll"] = "taxesPayroll";
    EProspectFileGroups["majorContracts"] = "majorContracts";
    EProspectFileGroups["payrollRegister"] = "payrollRegister";
    EProspectFileGroups["litigationSummary"] = "litigationSummary";
    EProspectFileGroups["litigation"] = "litigation";
    EProspectFileGroups["itSystems"] = "itSystems";
    EProspectFileGroups["trademark"] = "trademark";
    EProspectFileGroups["websites"] = "websites";
    EProspectFileGroups["perfectionCertificate"] = "perfectionCertificate";
    EProspectFileGroups["other"] = "other";
    EProspectFileGroups["fieldAppraisal"] = "fieldAppraisal";
    EProspectFileGroups["confidential"] = "confidential";
    EProspectFileGroups["confidentialPersonalFinancial"] = "confidentialPersonalFinancial";
    EProspectFileGroups["confidentialDriverLicenses"] = "confidentialDriverLicenses";
    EProspectFileGroups["confidentialReferences"] = "confidentialReferences";
})(EProspectFileGroups || (exports.EProspectFileGroups = EProspectFileGroups = {}));
exports.prospectFileGroups = [
    EProspectFileGroups.borrowingBase,
    EProspectFileGroups.corporateDocuments,
    EProspectFileGroups.financialsBankInformation,
    EProspectFileGroups.financialsBankInformation_historicalFinancials,
    EProspectFileGroups.financialsBankInformation_bankStatements,
    EProspectFileGroups.financialsBankInformation_projections,
    EProspectFileGroups.collateralSales,
    EProspectFileGroups.taxes,
    EProspectFileGroups.taxesIncome,
    EProspectFileGroups.taxesProperty,
    EProspectFileGroups.taxesPayroll,
    EProspectFileGroups.majorContracts,
    EProspectFileGroups.payrollRegister,
    EProspectFileGroups.litigationSummary,
    EProspectFileGroups.litigation,
    EProspectFileGroups.itSystems,
    EProspectFileGroups.trademark,
    EProspectFileGroups.websites,
    EProspectFileGroups.perfectionCertificate,
    EProspectFileGroups.other,
    EProspectFileGroups.confidential,
    EProspectFileGroups.confidentialPersonalFinancial,
    EProspectFileGroups.confidentialDriverLicenses,
    EProspectFileGroups.confidentialReferences,
    EProspectFileGroups.fieldAppraisal,
    ProspectInfoStageOne_model_1.ExternalProspectStageOneTables.detailsOfCurrentDebt,
    ProspectInfoStageOne_model_1.ExternalProspectStageOneTables.litigation,
    ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.financialInformation,
    ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.accountsReceivables,
    ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.inventoryInformationFiles,
    ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.equipment,
    ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.addressesOfOffices,
    ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.addressesOfWarehouses,
    ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.listOfManagers,
    ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.listOfShareholders,
    ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.listOfOfficers,
    ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.itSystems,
    ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.insuranceBrokers,
    ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.insurancePolicies,
    ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.accountsReceivablesExtra,
    ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.inventoryInformation,
];
exports.prospectFileGroupsMap = {
    [EProspectFileGroups.borrowingBase]: 'Borrowing Base',
    [EProspectFileGroups.corporateDocuments]: 'Collateral & Sales',
    [EProspectFileGroups.financialsBankInformation]: 'Financials & Bank Information',
    [EProspectFileGroups.collateralSales]: 'Collateral & Sales',
    [EProspectFileGroups.taxes]: 'Taxes',
    [EProspectFileGroups.taxesIncome]: 'Upload Payroll Tax Statements & Proof of Payment',
    [EProspectFileGroups.taxesProperty]: 'Upload Income Tax Returns',
    [EProspectFileGroups.taxesPayroll]: 'Upload Personal Property Tax Statements & Proof of Payment',
    [EProspectFileGroups.majorContracts]: 'Major Contracts',
    [EProspectFileGroups.payrollRegister]: 'Payroll Register',
    [EProspectFileGroups.litigationSummary]: 'Litigation Summary',
    [EProspectFileGroups.fieldAppraisal]: 'Field Appraisal or Audit Requests',
    [EProspectFileGroups.confidential]: 'Confidential',
    [EProspectFileGroups.confidentialPersonalFinancial]: 'Personal Financial Statements',
    [EProspectFileGroups.confidentialDriverLicenses]: 'Driver Licenses',
    [EProspectFileGroups.confidentialReferences]: 'References',
    [ProspectInfoStageOne_model_1.ExternalProspectStageOneTables.detailsOfCurrentDebt]: 'Details Of CurrentDebt',
    [ProspectInfoStageOne_model_1.ExternalProspectStageOneTables.litigation]: 'Summary of Litigation',
    [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.financialInformation]: 'Financial Information',
    [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.accountsReceivables]: 'Accounts Receivables',
    [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.inventoryInformationFiles]: 'Inventory Information Files',
    [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.addressesOfOffices]: 'Addresses Of Offices',
    [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.addressesOfWarehouses]: 'Addresses Of Warehouses',
    [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.equipment]: 'Equipment',
    [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.listOfManagers]: 'List Of Managers',
    [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.listOfShareholders]: 'List Of Shareholders',
    [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.listOfOfficers]: 'List Of Officers',
    [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.itSystems]: 'IT Systems',
    [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.insuranceBrokers]: 'Insurance Brokers',
    [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.insurancePolicies]: 'Insurance Brokers',
    [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.accountsReceivablesExtra]: 'Accounts Receivables Extra',
    [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.inventoryInformation]: 'Inventory Information',
};
exports.NO_ROW_ID = '__no_row__';
const initialFileGroups = () => exports.prospectFileGroups.reduce((acc, g) => {
    return { ...acc, [g]: { [exports.NO_ROW_ID]: [] } };
}, {});
exports.initialFileGroups = initialFileGroups;
const externalProspectInitialInfo = () => ({
    isLocked: false,
    lastSentDate: null,
    info: {
        stageOne: {
            companyLegalName: '',
            companyLegalAddress: '',
            companyCorrespondenceAddress: '',
            DBANames: '',
            websiteAddress: '',
            businessDescription: '',
            [ProspectInfoStageOne_model_1.ExternalProspectStageOneTables.litigation]: [
                {
                    _id: (0, main_helper_1.getUUID)(),
                    title: 'Describe any previous, current or threatened litigation. If no litigation, please state “No previous, current or threatened litigation".',
                    comment: '',
                },
            ],
            [ProspectInfoStageOne_model_1.ExternalProspectStageOneTables.detailsOfCurrentDebt]: [],
        },
        stageTwo: {
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.listOfShareholders]: [],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.listOfOfficers]: [],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.listOfManagers]: [],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.addressesOfOffices]: [],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.addressesOfWarehouses]: [],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.topCustomers]: [
                { _id: (0, main_helper_1.getUUID)(), name: '', value: '' },
                { _id: (0, main_helper_1.getUUID)(), name: '', value: '' },
                { _id: (0, main_helper_1.getUUID)(), name: '', value: '' },
                { _id: (0, main_helper_1.getUUID)(), name: '', value: '' },
                { _id: (0, main_helper_1.getUUID)(), name: '', value: '' },
            ],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.itSystems]: [],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.insuranceBrokers]: [],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.insurancePolicies]: [],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.financialInformation]: [
                {
                    _id: (0, main_helper_1.getUUID)(),
                    _sharepointFolder: EProspectFileGroups.financialsBankInformation_historicalFinancials,
                    title: 'Prior 2 years and YTD Income Statement & Balance Sheet in Excel Format',
                },
                {
                    _id: (0, main_helper_1.getUUID)(),
                    _sharepointFolder: EProspectFileGroups.financialsBankInformation_projections,
                    title: 'Currently Monthly Projections',
                },
                {
                    _id: (0, main_helper_1.getUUID)(),
                    _sharepointFolder: EProspectFileGroups.financialsBankInformation_bankStatements,
                    title: 'Last 3 Month Bank Statements',
                },
            ],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.accountsReceivables]: [
                {
                    _id: (0, main_helper_1.getUUID)(),
                    _sharepointFolder: EProspectFileGroups.accountsPayables,
                    title: 'Excel Format: Current and past 12 months A/P aging report by invoice date',
                },
                {
                    _id: (0, main_helper_1.getUUID)(),
                    _sharepointFolder: EProspectFileGroups.receivables,
                    title: 'Excel Format: Current and past 12 months A/R aging report by invoice date',
                },
                {
                    _id: (0, main_helper_1.getUUID)(),
                    _sharepointFolder: EProspectFileGroups.receivables,
                    title: 'Excel Format: A/R dilution (write-offs) for the trailing 3 months and 12 months',
                },
                {
                    _id: (0, main_helper_1.getUUID)(),
                    _sharepointFolder: EProspectFileGroups.receivables,
                    title: 'Excel Format: Outstanding / held checks list',
                },
                {
                    _id: (0, main_helper_1.getUUID)(),
                    _sharepointFolder: EProspectFileGroups.receivables,
                    title: 'Excel Format: Average A/R and A/P turnover in days for the trailing 3 months and 12 months',
                },
            ],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.accountsReceivablesLists]: [
                {
                    _id: (0, main_helper_1.getUUID)(),
                    title: 'Excel Format: Customer list with name, contact name, phone, email and address',
                },
                {
                    _id: (0, main_helper_1.getUUID)(),
                    title: 'Excel Format: Vendor list with name, contact name, phone, email and address',
                },
            ],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.accountsReceivablesExtra]: [
                {
                    _id: (0, main_helper_1.getUUID)(),
                    title: 'Describe any problems collecting AR in the last 2 years.',
                    comment: '',
                },
                {
                    _id: (0, main_helper_1.getUUID)(),
                    title: 'Detail any relationships where AR and AP are to the same person (i.e. a supplier is also a customer)',
                    comment: '',
                },
            ],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.accountsReceivablesContacts]: [],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.inventoryInformation]: [],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.inventoryInformationDetails]: [
                {
                    _id: (0, main_helper_1.getUUID)(),
                    title: 'How often is a physical inventory conducted?',
                },
                {
                    _id: (0, main_helper_1.getUUID)(),
                    title: 'What is the historical physical inventory discrepancy for the past 2 years?',
                },
            ],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.inventoryInformationFiles]: [
                {
                    _id: (0, main_helper_1.getUUID)(),
                    title: 'Excel Format: Current inventory report by SKU. Include breakdown by Raw, WIP and FG',
                },
                {
                    _id: (0, main_helper_1.getUUID)(),
                    title: 'Excel Format: If possible either (a) inventory turnover report by SKU or (b) sales by SKU by month for trailing 12 months',
                },
                { _id: (0, main_helper_1.getUUID)(), title: 'Excel Format: Old and/or obsolete / damaged inventory report' },
            ],
            [ProspectInfoStageTwo_model_1.ExternalProspectStageTwoTables.equipment]: [
                { _id: (0, main_helper_1.getUUID)(), title: 'Current schedule of fixed assets and depreciation schedule' },
                {
                    _id: (0, main_helper_1.getUUID)(),
                    title: 'Depreciation schedule for such assets, specifically for the equipment for this proposed financing',
                },
                { _id: (0, main_helper_1.getUUID)(), title: 'Copies of invoices for equipment purchases over $50,000' },
                { _id: (0, main_helper_1.getUUID)(), title: 'Copies of any calibration certificates and schedule of due dates' },
                { _id: (0, main_helper_1.getUUID)(), title: 'Copies of titles for titled equipment' },
                { _id: (0, main_helper_1.getUUID)(), title: 'Copy of any prior appraisals' },
            ],
        },
        notes: [],
    },
});
exports.externalProspectInitialInfo = externalProspectInitialInfo;
exports.baseFields = ['_id', 'industry', 'status', 'revolverAmount', 'termAmount', 'keyDates'];
const ProspectInfoRowValidationSchema = joi_1.default.object({
    _id: joi_1.default.string().allow(exports.NO_ROW_ID),
    name: joi_1.default.string().allow('', null),
    value: joi_1.default.string().allow('', null),
    extraValue: joi_1.default.string().allow('', null),
});
exports.ProspectInfoExternalValidationSchema = joi_1.default.object({
    companyLegalName: joi_1.default.string().allow('', null),
    companyLegalAddress: joi_1.default.string().allow('', null),
    companyCorrespondenceAddress: joi_1.default.string().allow('', null),
    DBANames: joi_1.default.string().allow('', null),
    websiteAddress: joi_1.default.string().allow('', null),
    businessDescription: joi_1.default.string().allow('', null),
    listOfShareholders: joi_1.default.array().items(ProspectInfoRowValidationSchema),
    listOfOfficers: joi_1.default.array().items(ProspectInfoRowValidationSchema),
    listOfManagers: joi_1.default.array().items(ProspectInfoRowValidationSchema),
    addressesOfOffices: joi_1.default.array().items(ProspectInfoRowValidationSchema),
    addressesOfWarehouses: joi_1.default.array().items(ProspectInfoRowValidationSchema),
    top5Customers: joi_1.default.array().items(ProspectInfoRowValidationSchema),
});
exports.ProspectInfoValidationSchema = joi_1.default.object({
    isLocked: joi_1.default.boolean().allow(null),
    lastSentDate: joi_1.default.date().allow(null),
});
exports.ProspectValidationSchema = joi_1.default.object({
    _id: joi_1.default.string(),
    isDeclined: joi_1.default.boolean().allow(null),
    name: joi_1.default.string().required(),
    industryId: joi_1.default.string().required(),
    status: joi_1.default.string().valid(...Object.values(EProspectStatus)).required(),
    probability: joi_1.default.number().required(),
    depositRequested: joi_1.default.number().required(),
    revolver: joi_1.default.object({
        commitment: joi_1.default.number(),
        expected: joi_1.default.number(),
        maturity: joi_1.default.number().integer(),
    }).or('commitment', 'expected', 'maturity'),
    term: joi_1.default.object({
        commitment: joi_1.default.number(),
        expected: joi_1.default.number(),
        maturity: joi_1.default.number().integer(),
    }).or('commitment', 'expected', 'maturity'),
    collaterals: joi_1.default.object({
        equipment: joi_1.default.boolean().required(),
        inventory: joi_1.default.boolean().required(),
        receivables: joi_1.default.boolean().required(),
        other: joi_1.default.boolean().required(),
    }),
    keyDates: joi_1.default.object({
        lastContact: joi_1.default.date(),
        receivedDate: joi_1.default.date(),
        LOISubmitted: joi_1.default.date().allow(null),
        DDStarted: joi_1.default.date().allow(null),
        expectedFunding: joi_1.default.date().allow(null),
        dropDate: joi_1.default.date().allow(null),
    }),
    priority: joi_1.default.string().valid(...Object.values(EProspectPriority)).required(),
    businessDescription: joi_1.default.string().max(textFieldMaxLength).allow(''),
    comments: joi_1.default.string().max(textFieldMaxLength).allow(''),
    collateralDescription: joi_1.default.string().max(textFieldMaxLength).allow(''),
    declineReason: joi_1.default.string().valid(...Object.values(EProspectDeclineReason)),
    sourceId: joi_1.default.string().required(),
    // closingPoints: Joi.number().required().allow(null, 0).default(0),
    // expectedLoanYield: Joi.number().required().allow(null, 0).default(0),
    state: joi_1.default.string().required(),
    contacts: joi_1.default.array().items(joi_1.default.object({
        name: joi_1.default.string().required().allow('', null).default(''),
        email: joi_1.default.string().required().allow('', null).default(''),
        phone: joi_1.default.string().required().allow('', null).default(''),
        comment: joi_1.default.string().required().allow('', null).default(''),
        companyName: joi_1.default.string().required().allow('', null).default(''),
    })),
    underwriterIds: joi_1.default.array().items(joi_1.default.string()),
    auditorIds: joi_1.default.array().items(joi_1.default.string()),
    appraiserIds: joi_1.default.array().items(joi_1.default.string()),
    acceptedFiles: joi_1.default.array().items(joi_1.default.string()).allow(null),
}).concat(exports.ProspectInfoValidationSchema);
const contactSchema = new mongoose_1.default.Schema({
    name: {
        type: String,
        required: false,
        default: '',
    },
    email: {
        type: String,
        required: false,
        default: '',
    },
    phone: {
        type: String,
        required: false,
        default: '',
    },
    comment: {
        type: String,
        required: false,
        default: '',
    },
    companyName: {
        type: String,
        required: false,
        default: '',
    },
}, { _id: false });
const ProspectInfoSchema = {
    isLocked: {
        type: Boolean,
    },
    lastSentDate: {
        type: Date,
    },
    info: {
        stageOne: ProspectInfoStageOne_model_1.ProspectInfoStageOne,
        stageTwo: ProspectInfoStageTwo_model_1.ProspectInfoStageTwo,
        notes: { type: [ProspectInfoNote_model_1.CRMProspectInfoNoteSchema], default: [] },
    },
};
exports.ProspectSchema = new mongoose_1.default.Schema({
    isLocked: {
        type: Boolean,
    },
    isDeclined: {
        type: Boolean,
    },
    name: {
        type: String,
        trim: true,
    },
    industryId: {
        type: mongoose_1.default.Schema.Types.ObjectId,
        ref: _models_1.MODEL_NAMES.CRMProspectIndustries,
    },
    status: {
        type: String,
        enum: Object.values(EProspectStatus),
    },
    probability: {
        type: Number,
    },
    revolver: {
        commitment: {
            type: Number,
        },
        expected: {
            type: Number,
        },
        maturity: {
            type: Number,
        },
    },
    term: {
        commitment: {
            type: Number,
        },
        expected: {
            type: Number,
        },
        maturity: {
            type: Number,
        },
    },
    priority: {
        type: String,
        enum: Object.values(EProspectPriority),
    },
    declineReason: {
        type: String,
        enum: Object.values(EProspectDeclineReason),
    },
    businessDescription: {
        type: String,
    },
    comments: {
        type: String,
    },
    collateralDescription: {
        type: String,
    },
    sourceId: {
        type: mongoose_1.default.Schema.Types.ObjectId,
        ref: _models_1.MODEL_NAMES.CRMProspectSources,
    },
    collaterals: {
        equipment: {
            type: Boolean,
        },
        inventory: {
            type: Boolean,
        },
        receivables: {
            type: Boolean,
        },
        other: {
            type: Boolean,
        },
    },
    closingPoints: {
        type: Number,
    },
    expectedLoanYield: {
        type: Number,
    },
    depositRequested: {
        type: Number,
    },
    keyDates: {
        lastContact: {
            type: Date,
        },
        receivedDate: {
            type: Date,
        },
        LOISubmitted: {
            type: Date,
        },
        DDStarted: {
            type: Date,
        },
        expectedFunding: {
            type: Date,
        },
        dropDate: {
            type: Date,
        },
    },
    state: {
        type: String,
    },
    contacts: [contactSchema],
    ...ProspectInfoSchema,
    underwriterIds: [{
            type: mongoose_1.default.Schema.Types.ObjectId,
            ref: _models_1.MODEL_NAMES.underwriters,
        }],
    auditorIds: [{
            type: mongoose_1.default.Schema.Types.ObjectId,
            ref: _models_1.MODEL_NAMES.auditors,
        }],
    appraiserIds: [{
            type: mongoose_1.default.Schema.Types.ObjectId,
            ref: _models_1.MODEL_NAMES.appraiser,
        }],
}, {
    timestamps: { createdAt: true, updatedAt: true },
    versionKey: false,
});
exports.Prospect = mongoose_1.default.model(_models_1.MODEL_NAMES.CRMProspects, exports.ProspectSchema);
