"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 core_1 = require("@medplum/core");
const zod_1 = __importDefault(require("zod"));
exports.fields = {
    messageDataPoint: {
        id: 'messageDataPoint',
        label: 'Message Data Point',
        description: 'The message to parse. Use this if you want to use a data point for the message.',
        type: extensions_core_1.FieldType.STRING,
        required: false,
    },
    message: {
        id: 'message',
        label: 'Message',
        description: 'The message to parse. Use this if you want to use a text for the message.',
        type: extensions_core_1.FieldType.TEXT,
        required: false,
    },
    schema: {
        id: 'schema',
        label: 'Schema',
        description: 'JSON schema defining the structure to extract from the message. Example: {"name": "string", "age": "number", "email": "string"}',
        type: extensions_core_1.FieldType.JSON,
        required: true,
    },
    instructions: {
        id: 'instructions',
        label: 'Instructions',
        description: 'Add additional instructions prompt for the LLM',
        type: extensions_core_1.FieldType.TEXT,
        required: false,
    },
};
exports.FieldsValidationSchema = zod_1.default.object({
    message: zod_1.default.string().optional(),
    messageDataPoint: zod_1.default.string().optional(),
    schema: zod_1.default.string().transform((str, ctx) => {
        if ((0, core_1.isEmpty)(str)) {
            ctx.addIssue({
                code: 'custom',
                message: 'Schema is required',
            });
            return zod_1.default.NEVER;
        }
        try {
            const parsed = JSON.parse(str);
            if (typeof parsed !== 'object' ||
                parsed === null ||
                Array.isArray(parsed)) {
                ctx.addIssue({
                    code: 'custom',
                    message: 'Schema must be a JSON object',
                });
                return zod_1.default.NEVER;
            }
            return parsed;
        }
        catch (e) {
            ctx.addIssue({
                code: 'custom',
                message: 'Invalid JSON schema',
            });
            return zod_1.default.NEVER;
        }
    }),
    instructions: zod_1.default.string().optional(),
});
//# sourceMappingURL=fields.js.map