import { Representative } from "./Identity";
import { getStateAbbreviation } from "../components/business-forms/utils/helpers";
import { CountryCode } from "../utils/country-codes";
// Normalize various incoming country representations to strict CountryCode values
const normalizeCountry = (value) => {
    const v = (value || '').toString().trim().toUpperCase();
    if (v === 'US' || v === 'USA' || v === CountryCode.USA)
        return CountryCode.USA;
    if (v === 'CA' || v === 'CAN' || v === CountryCode.CAN)
        return CountryCode.CAN;
    return CountryCode.USA;
};
export var BusinessFormServerErrors;
(function (BusinessFormServerErrors) {
    BusinessFormServerErrors["fetchData"] = "Error retrieving business data";
    BusinessFormServerErrors["patchData"] = "Error updating business data";
})(BusinessFormServerErrors || (BusinessFormServerErrors = {}));
export var BusinessClassification;
(function (BusinessClassification) {
    BusinessClassification["sole_proprietor"] = "sole_proprietor";
    BusinessClassification["partnership"] = "partnership";
    BusinessClassification["corporation"] = "corporation";
    BusinessClassification["public_company"] = "public_company";
    BusinessClassification["limited"] = "limited";
    BusinessClassification["non_profit"] = "non_profit";
    BusinessClassification["government"] = "government";
})(BusinessClassification || (BusinessClassification = {}));
export class Address {
    constructor(address) {
        this.id = address.id;
        this.platform_account_id = address.platform_account_id;
        this.line1 = address.line1;
        this.line2 = address.line2;
        this.postal_code = address.postal_code;
        this.city = address.city;
        this.state = getStateAbbreviation(address.state);
        this.country = normalizeCountry(address.country);
        this.created_at = address.created_at;
        this.updated_at = address.updated_at;
    }
    get payload() {
        return {
            platform_account_id: this.platform_account_id || '',
            line1: this.line1 || '',
            line2: this.line2 || '',
            postal_code: this.postal_code || '',
            city: this.city || '',
            state: this.state || '',
            country: this.country || '',
        };
    }
}
export class AdditionalQuestions {
    constructor(additionalQuestions) {
        this.business_revenue = additionalQuestions.business_revenue;
        this.business_payment_volume = additionalQuestions.business_payment_volume;
        this.business_average_transaction_amount = additionalQuestions.business_average_transaction_amount;
        this.business_when_service_received =
            additionalQuestions.business_when_service_received;
        this.business_recurring_payments =
            additionalQuestions.business_recurring_payments;
        this.business_recurring_payments_percentage =
            additionalQuestions.business_recurring_payments_percentage;
        this.business_seasonal = additionalQuestions.business_seasonal;
        this.business_other_payment_details =
            additionalQuestions.business_other_payment_details;
    }
    get payload() {
        return {
            business_revenue: this.business_revenue || '',
            business_payment_volume: this.business_payment_volume || '',
            business_average_transaction_amount: this.business_average_transaction_amount || '',
            business_when_service_received: this.business_when_service_received || '',
            business_recurring_payments: this.business_recurring_payments || '',
            business_recurring_payments_percentage: this.business_recurring_payments_percentage || '',
            business_seasonal: this.business_seasonal || '',
            business_other_payment_details: this.business_other_payment_details || '',
        };
    }
}
export class CoreBusinessInfo {
    constructor(coreBusinessInfo) {
        this.classification = coreBusinessInfo.classification;
        this.legal_name = coreBusinessInfo.legal_name;
        this.doing_business_as = coreBusinessInfo.doing_business_as;
        this.industry = coreBusinessInfo.industry;
        this.tax_id = coreBusinessInfo.tax_id;
        this.tax_id_last4 = coreBusinessInfo.tax_id_last4;
        this.website_url = coreBusinessInfo.website_url;
        this.email = coreBusinessInfo.email;
        this.phone = coreBusinessInfo.phone;
        this.date_of_incorporation = coreBusinessInfo.date_of_incorporation;
    }
    get payload() {
        return Object.assign(Object.assign({ classification: this.classification || '', legal_name: this.legal_name || '', doing_business_as: this.doing_business_as || '', industry: this.industry || '' }, (!this.tax_id_last4 && { tax_id: this.tax_id || '' })), { website_url: this.website_url || '', email: this.email || '', phone: this.phone || '', date_of_incorporation: this.date_of_incorporation || '' });
    }
}
export class Business {
    constructor(business) {
        this.additional_questions = business.additional_questions
            ? new AdditionalQuestions(business.additional_questions)
            : null;
        this.associated_accounts = business.associated_accounts;
        this.classification = business.classification;
        this.bank_accounts = business.bank_accounts;
        this.created_at = business.created_at;
        this.documents = business.documents;
        this.doing_business_as = business.doing_business_as;
        this.email = business.email;
        this.id = business.id;
        this.industry = business.industry;
        this.legal_address = (business === null || business === void 0 ? void 0 : business.legal_address)
            ? new Address(business.legal_address)
            : null;
        this.legal_name = business.legal_name;
        this.metadata = business.metadata;
        this.owners = business.owners;
        this.phone = business.phone;
        this.platform_account_id = business.platform_account_id;
        this.product_categories = business.product_categories;
        this.representative = business.representative
            ? new Representative(business.representative)
            : null;
        this.tax_id = business.tax_id;
        this.tax_id_last4 = business.tax_id_last4;
        this.terms_conditions_accepted = business.terms_conditions_accepted;
        this.updated_at = business.updated_at;
        this.website_url = business.website_url;
        this.date_of_incorporation = business.date_of_incorporation;
        this.country_of_establishment = normalizeCountry(business.country_of_establishment);
        this.bank_account_verification = business.bank_account_verification;
    }
    get payload() {
        return Object.assign(Object.assign({ additional_questions: new AdditionalQuestions(this.additional_questions)
                .payload, classification: this.classification || '', doing_business_as: this.doing_business_as || '', email: this.email || '', industry: this.industry || '', legal_address: new Address(this.legal_address).payload, legal_name: this.legal_name || '', metadata: this.metadata || {}, owners: this.owners.map((owner) => ({ id: owner.id })), phone: this.phone || '', platform_account_id: this.platform_account_id || '', representative: new Representative(this.representative).payload }, (!this.tax_id_last4 && { tax_id: this.tax_id || '' })), { tax_id_last4: this.tax_id_last4 || '', website_url: this.website_url || '', date_of_incorporation: this.date_of_incorporation || '', country_of_establishment: this.country_of_establishment || CountryCode.USA });
    }
}
