'use strict';

var index_esm = require('./index.esm-BNETBIV_.js');
var schemaValidations = require('./schema-validations-Cs0mSKR7.js');
var Business = require('./Business-oBifyXkW.js');
var countryConfig = require('./country-config-C1bWmF8P.js');

// Base schema (no country-specific rules for classification/tax id)
const baseBusinessCoreInfoSchema = (allowOptionalFields) => {
    const schema = index_esm.create$3({
        legal_name: schemaValidations.businessNameValidation.required('Enter legal name'),
        website_url: schemaValidations.websiteUrlValidation.required('Enter business website url'),
        email: schemaValidations.emailValidation.required('Enter business email'),
        phone: schemaValidations.phoneValidation.required('Enter phone number'),
        doing_business_as: schemaValidations.doingBusinessAsValidation.nullable(),
        classification: schemaValidations.businessClassificationValidation.required('Select business classification'),
        industry: schemaValidations.industryValidation.required('Enter a business industry'),
        date_of_incorporation: schemaValidations.dateOfIncorporationValidation.required('Enter date of registration'),
    });
    const easySchema = index_esm.create$3({
        legal_name: schemaValidations.businessNameValidation.required('Enter legal name'),
        website_url: schemaValidations.websiteUrlValidation.nullable(),
        email: schemaValidations.emailValidation.nullable(),
        phone: schemaValidations.phoneValidation.nullable(),
        doing_business_as: schemaValidations.doingBusinessAsValidation.nullable(),
        classification: schemaValidations.businessClassificationValidation.nullable(),
        industry: schemaValidations.industryValidation.nullable(),
        tax_id: schemaValidations.taxIdValidation.nullable(),
        date_of_incorporation: schemaValidations.dateOfIncorporationValidation.nullable(),
    });
    return allowOptionalFields ? easySchema : schema;
};
// Country-specific schema convenience wrappers
const businessCoreInfoSchemaUSA = (allowOptionalFields) => baseBusinessCoreInfoSchema(allowOptionalFields).concat(index_esm.create$3({
    classification: index_esm.create$6().required('Select business classification'),
    tax_id: schemaValidations.makeTaxIdValidation(Business.CountryCode.USA)
        .when('tax_id_last4', {
        is: (val) => !val,
        then: (schema) => schema.required(`Enter valid ${countryConfig.countryLabels.USA.taxIdLabel} without dashes`),
        otherwise: (schema) => schema.nullable(),
    }),
}));
const businessCoreInfoSchemaCAN = (allowOptionalFields) => baseBusinessCoreInfoSchema(allowOptionalFields).concat(index_esm.create$3({
    classification: index_esm.create$6().required('Select business classification'),
    tax_id: schemaValidations.makeTaxIdValidation(Business.CountryCode.CAN)
        .when('tax_id_last4', {
        is: (val) => !val,
        then: (schema) => schema.notRequired().nullable(),
        otherwise: (schema) => schema.nullable(),
    }),
}));

const additionalQuestionsSchema = (allowOptionalFields) => {
    const schema = index_esm.create$3({
        business_revenue: schemaValidations.revenueValidation.required('Enter business revenue'),
        business_payment_volume: schemaValidations.paymentVolumeValidation.required('Enter business payment volume'),
        business_average_transaction_amount: schemaValidations.revenueValidation.required('Enter average transaction amount'),
        business_when_service_received: schemaValidations.whenServiceReceivedValidation.required('Select when service is received'),
        business_other_payment_details: schemaValidations.otherPaymentDetailsValidation.nullable(),
    });
    const easySchema = index_esm.create$3({
        business_revenue: schemaValidations.revenueValidation.nullable(),
        business_payment_volume: schemaValidations.paymentVolumeValidation.nullable(),
        business_average_transaction_amount: schemaValidations.revenueValidation.nullable(),
        business_when_service_received: schemaValidations.whenServiceReceivedValidation.nullable(),
        business_other_payment_details: schemaValidations.otherPaymentDetailsValidation.nullable(),
    });
    return allowOptionalFields ? easySchema : schema;
};

// Internal USA schemas
const schemaUSA$1 = () => index_esm.create$3({
    line1: schemaValidations.lineOneValidation.nullable(),
    line2: schemaValidations.lineTwoValidation.nullable(),
    city: schemaValidations.cityValidation.nullable(),
    state: index_esm.create$6().nullable(),
    postal_code: index_esm.create$6().nullable(),
});
const strictSchemaUSA$1 = () => index_esm.create$3({
    line1: schemaValidations.lineOneValidation.required('Enter street address'),
    line2: schemaValidations.lineTwoValidation.nullable(),
    city: schemaValidations.cityValidation.required('Enter city'),
    state: index_esm.create$6().required('Select state'),
    postal_code: schemaValidations.makePostalValidation(Business.CountryCode.USA).required('Enter postal code'),
});
// Internal CAN schemas
const schemaCAN$1 = () => index_esm.create$3({
    line1: schemaValidations.lineOneValidation.nullable(),
    line2: schemaValidations.lineTwoValidation.nullable(),
    city: schemaValidations.cityValidation.nullable(),
    state: index_esm.create$6().nullable(),
    postal_code: index_esm.create$6().nullable(),
});
const strictSchemaCAN$1 = () => index_esm.create$3({
    line1: schemaValidations.lineOneValidation.required('Enter street address'),
    line2: schemaValidations.lineTwoValidation.nullable(),
    city: schemaValidations.cityValidation.required('Enter city'),
    state: index_esm.create$6().required('Select province or state'),
    postal_code: schemaValidations.makePostalValidation(Business.CountryCode.CAN).required('Enter postal code'),
});
// Public API
const addressSchemaUSA = (allowOptionalFields) => allowOptionalFields ? schemaUSA$1() : strictSchemaUSA$1();
const addressSchemaCAN = (allowOptionalFields) => allowOptionalFields ? schemaCAN$1() : strictSchemaCAN$1();
// Country-keyed mapping
const addressSchemaByCountry = {
    [Business.CountryCode.USA]: addressSchemaUSA,
    [Business.CountryCode.CAN]: addressSchemaCAN,
};

// Internal USA schemas
const schemaUSA = (role) => index_esm.create$3({
    name: schemaValidations.identityNameValidation.required(`Enter ${role} name`),
    title: schemaValidations.identityTitleValidation.nullable(),
    email: schemaValidations.emailValidation.nullable(),
    phone: schemaValidations.phoneValidation.nullable(),
    dob_full: schemaValidations.dobValidation(role).nullable(),
    ssn_last4: index_esm.create$6().nullable(),
    identification_number: schemaValidations.ssnValidation.nullable(),
    ownership_percentage: schemaValidations.ownershipPercentageValidation.nullable(),
    address: addressSchemaUSA(true),
});
const strictSchemaUSA = (role) => index_esm.create$3({
    name: schemaValidations.identityNameValidation.required(`Enter ${role} name`),
    title: schemaValidations.identityTitleValidation.required(`Enter ${role} title`),
    email: schemaValidations.emailValidation.required(`Enter ${role} email`),
    phone: schemaValidations.phoneValidation.required('Enter phone number'),
    dob_full: schemaValidations.dobValidation(role).required('Enter date of birth'),
    ssn_last4: index_esm.create$6().nullable(),
    // ssn required unless last4 provided (handled inside ssnValidation)
    identification_number: schemaValidations.ssnValidation,
    ownership_percentage: role === 'owner'
        ? schemaValidations.ownershipPercentageValidation.required('Enter ownership percentage')
        : schemaValidations.ownershipPercentageValidation.nullable(),
    address: addressSchemaUSA(false),
});
// Internal CAN schemas
const schemaCAN = (role) => index_esm.create$3({
    name: schemaValidations.identityNameValidation.required(`Enter ${role} name`),
    title: schemaValidations.identityTitleValidation.nullable(),
    email: schemaValidations.emailValidation.nullable(),
    phone: schemaValidations.phoneValidation.nullable(),
    dob_full: schemaValidations.dobValidation(role).nullable(),
    ssn_last4: index_esm.create$6().nullable(),
    identification_number: schemaValidations.makeIdentityNumberValidation(Business.CountryCode.CAN).nullable(),
    ownership_percentage: schemaValidations.ownershipPercentageValidation.nullable(),
    address: addressSchemaCAN(true),
});
const strictSchemaCAN = (role) => index_esm.create$3({
    name: schemaValidations.identityNameValidation.required(`Enter ${role} name`),
    title: schemaValidations.identityTitleValidation.required(`Enter ${role} title`),
    email: schemaValidations.emailValidation.required(`Enter ${role} email`),
    phone: schemaValidations.phoneValidation.required('Enter phone number'),
    dob_full: schemaValidations.dobValidation(role).required('Enter date of birth'),
    ssn_last4: index_esm.create$6().nullable(),
    identification_number: schemaValidations.makeIdentityNumberValidation(Business.CountryCode.CAN).nullable(),
    ownership_percentage: role === 'owner'
        ? schemaValidations.ownershipPercentageValidation.required('Enter ownership percentage')
        : schemaValidations.ownershipPercentageValidation.nullable(),
    address: addressSchemaCAN(false),
});
const identitySchemaUSA = (role, allowOptionalFields) => allowOptionalFields ? schemaUSA(role) : strictSchemaUSA(role);
const identitySchemaCAN = (role, allowOptionalFields) => allowOptionalFields ? schemaCAN(role) : strictSchemaCAN(role);
// Country-keyed mapping
const identitySchemaByCountry = {
    [Business.CountryCode.USA]: identitySchemaUSA,
    [Business.CountryCode.CAN]: identitySchemaCAN,
};

exports.additionalQuestionsSchema = additionalQuestionsSchema;
exports.addressSchemaByCountry = addressSchemaByCountry;
exports.addressSchemaCAN = addressSchemaCAN;
exports.addressSchemaUSA = addressSchemaUSA;
exports.businessCoreInfoSchemaCAN = businessCoreInfoSchemaCAN;
exports.businessCoreInfoSchemaUSA = businessCoreInfoSchemaUSA;
exports.identitySchemaByCountry = identitySchemaByCountry;
exports.identitySchemaCAN = identitySchemaCAN;
exports.identitySchemaUSA = identitySchemaUSA;
