"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.dynamicReadFields = dynamicReadFields;
const constants_1 = require("./constants");
async function dynamicReadFields(request, types, isCompany = false) {
    try {
        const response = await request(constants_1.base_url + `${isCompany ? 'companies' : 'leads'}/fields`, {
            method: 'GET',
            skipResponseCloning: true
        });
        const choices = {
            choices: response.data.data
                .filter(field => {
                return types.includes(field.type);
            })
                .map((field) => ({
                label: `${field.label} [${field.type}]`,
                value: field.name
            }))
        };
        if (choices.choices.length === 0) {
            return {
                choices: [],
                error: {
                    message: `No fields found for types: ${types.join(', ')}`,
                    code: 'no_fields_found'
                }
            };
        }
        return choices;
    }
    catch (err) {
        return {
            choices: [],
            error: {
                message: err.message ?? 'Unknown error: dynamicReadFields',
                code: err.code
            }
        };
    }
}
//# sourceMappingURL=dynamic-functions.js.map