"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 zod_1 = __importDefault(require("zod"));
const lodash_1 = require("lodash");
exports.fields = {
    fileType: {
        id: 'fileType',
        label: 'File type',
        description: 'The type of file to extract data from',
        type: extensions_core_1.FieldType.STRING,
        options: {
            dropdownOptions: [
                {
                    label: 'Image',
                    value: 'image',
                },
                {
                    label: 'PDF',
                    value: 'pdf',
                },
            ],
        },
        required: true,
    },
    fileUrl: {
        id: 'fileUrl',
        label: 'File URL',
        description: 'The URL of the file to extract data from',
        type: extensions_core_1.FieldType.STRING,
        required: true,
    },
    fieldsSchema: {
        id: 'fieldsSchema',
        label: 'Fields schema',
        description: 'Defines the structure of the fields to extract from the document. Providing a schema is optional but strongly recommended, as it significantly improves the accuracy of the extracted data.',
        type: extensions_core_1.FieldType.JSON,
        required: false,
    },
};
exports.FieldsValidationSchema = zod_1.default.object({
    fileType: zod_1.default.enum(['image', 'pdf']),
    fileUrl: zod_1.default.string().min(1),
    fieldsSchema: 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;
            return parsedJson;
        }
        catch (e) {
            ctx.addIssue({
                code: 'custom',
                message: 'Not a valid JSON object',
            });
            return zod_1.default.NEVER;
        }
    }),
});
//# sourceMappingURL=fields.js.map