"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldsValidationSchema = exports.fields = exports.zOcrProvider = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const lodash_1 = require("lodash");
const zod_1 = require("zod");
exports.zOcrProvider = zod_1.z.enum(['awell-landing-ai']);
const OcrProviderOptions = {
    'awell-landing-ai': 'Awell (Landing.ai)',
};
exports.fields = {
    faxId: {
        id: 'faxId',
        label: 'Fax Id',
        description: 'SRFax FaxDetailsID (the number after the "|" in FileName) or full FileName',
        type: extensions_core_1.FieldType.STRING,
        required: true,
    },
    ocrProvider: {
        id: 'ocrProvider',
        label: 'OCR Provider',
        description: 'The provider or service used for OCR',
        type: extensions_core_1.FieldType.STRING,
        required: true,
        options: {
            dropdownOptions: Object.entries(OcrProviderOptions).map(([key, value]) => ({
                label: value,
                value: key,
            })),
        },
    },
    ocrProviderApiKey: {
        id: 'ocrProviderApiKey',
        label: 'OCR Provider API Key',
        description: 'We advise using a obfuscated constant',
        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.z.object({
    faxId: zod_1.z.string().min(1),
    ocrProvider: exports.zOcrProvider,
    ocrProviderApiKey: zod_1.z.string().min(1),
    fieldsSchema: zod_1.z
        .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.z.NEVER;
        }
    }),
});
//# sourceMappingURL=fields.js.map