"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldsSchema = exports.dataPoints = exports.fields = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const lodash_1 = require("lodash");
const zod_1 = require("zod");
exports.fields = {
    campaignId: {
        id: 'campaignId',
        label: 'Campaign ID',
        type: extensions_core_1.FieldType.STRING,
        required: true,
        description: 'The ID of the Gridspace autodialer campaign.',
    },
    phoneNumber: {
        id: 'phoneNumber',
        label: 'Phone Number',
        type: extensions_core_1.FieldType.STRING,
        stringType: extensions_core_1.StringType.PHONE,
        required: true,
        description: 'The phone number to call.',
    },
    data: {
        id: 'data',
        label: 'Data',
        type: extensions_core_1.FieldType.JSON,
        required: true,
        description: 'Any additional data to be passed to the campaign. Should be a JSON object.',
    },
};
exports.dataPoints = {
    data: {
        key: 'data',
        valueType: 'json',
    },
    num_uploaded_contacts: {
        key: 'num_uploaded_contacts',
        valueType: 'number',
    },
};
exports.FieldsSchema = zod_1.z.object({
    campaignId: zod_1.z.string(),
    phoneNumber: zod_1.z.string(),
    data: zod_1.z.string().transform((str, ctx) => {
        if ((0, lodash_1.isNil)(str) || (0, lodash_1.isEmpty)(str)) {
            return {};
        }
        try {
            const parsedJson = JSON.parse(str);
            if ((0, lodash_1.isEmpty)(parsedJson)) {
                return {};
            }
            if (typeof parsedJson !== 'object' || Array.isArray(parsedJson)) {
                ctx.addIssue({
                    code: 'custom',
                    message: 'Data should be an object',
                });
                return zod_1.z.NEVER;
            }
            for (const key in parsedJson) {
                if (typeof parsedJson[key] !== 'string') {
                    ctx.addIssue({
                        code: 'custom',
                        message: `Value for key "${key}" must be a string`,
                    });
                    return zod_1.z.NEVER;
                }
            }
            return parsedJson;
        }
        catch (e) {
            ctx.addIssue({ code: 'custom', message: 'Invalid JSON' });
            return zod_1.z.NEVER;
        }
    }),
});
//# sourceMappingURL=config.js.map