"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldsValidationSchema = exports.fields = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const lodash_1 = require("lodash");
const zod_1 = __importDefault(require("zod"));
exports.fields = {
    email: {
        id: 'email',
        label: 'Email',
        description: 'The email of the contact',
        type: extensions_core_1.FieldType.STRING,
        required: true,
    },
    firstName: {
        id: 'firstName',
        label: 'First name',
        description: 'The first name of the contact',
        type: extensions_core_1.FieldType.STRING,
        required: false,
    },
    lastName: {
        id: 'lastName',
        label: 'Last name',
        description: 'The last name of the contact',
        type: extensions_core_1.FieldType.STRING,
        required: false,
    },
    phone: {
        id: 'phone',
        label: 'Phone',
        description: 'The phone number of the contact',
        type: extensions_core_1.FieldType.STRING,
        stringType: extensions_core_1.StringType.PHONE,
        required: false,
    },
    customProperties: {
        id: 'customProperties',
        label: 'Custom properties',
        description: 'An object of key-values pairs of custom properties of the contact',
        type: extensions_core_1.FieldType.JSON,
        required: false,
    },
};
exports.FieldsValidationSchema = zod_1.default.object({
    email: zod_1.default.string().min(1).email(),
    firstName: zod_1.default
        .string()
        .optional()
        .transform((val) => ((0, lodash_1.isEmpty)(val) ? undefined : val)),
    lastName: zod_1.default
        .string()
        .optional()
        .transform((val) => ((0, lodash_1.isEmpty)(val) ? undefined : val)),
    phone: zod_1.default
        .string()
        .optional()
        .transform((val) => ((0, lodash_1.isEmpty)(val) ? undefined : val)),
    customProperties: zod_1.default
        .string()
        .optional()
        .transform((str, ctx) => {
        if ((0, lodash_1.isNil)(str) || (0, lodash_1.isEmpty)(str))
            return undefined;
        try {
            const parsedJson = JSON.parse(str);
            if ((0, lodash_1.isEmpty)(parsedJson)) {
                return undefined;
            }
            if (typeof parsedJson !== 'object' || Array.isArray(parsedJson)) {
                ctx.addIssue({
                    code: 'custom',
                    message: 'The value should represent an object',
                });
                return zod_1.default.NEVER;
            }
            return parsedJson;
        }
        catch (e) {
            ctx.addIssue({ code: 'custom', message: 'Invalid JSON.' });
            return zod_1.default.NEVER;
        }
    }),
});
//# sourceMappingURL=fields.js.map