"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findAppointments = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const settings_1 = require("../../settings");
const client_1 = require("../../client");
const appointment_zod_1 = require("../../validation/appointment.zod");
const zod_1 = require("zod");
const config_1 = require("./config");
exports.findAppointments = {
    key: 'findAppointment',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Find Appointment',
    description: 'Retrieve appointments for a given patient, physician, practice, and/or times',
    fields: config_1.fields,
    previewable: true,
    supports_automated_retries: true,
    dataPoints: config_1.dataPoints,
    onEvent: async ({ payload, onComplete }) => {
        const { fields, settings } = (0, extensions_core_1.validate)({
            schema: zod_1.z.object({
                fields: config_1.FieldsValidationSchema,
                settings: settings_1.SettingsValidationSchema,
            }),
            payload,
        });
        const findAppiontmentsParams = appointment_zod_1.FindAppointmentFieldSchema.parse(fields);
        const client = (0, client_1.makeAPIClient)(settings);
        const resp = await client.findAppointments(findAppiontmentsParams);
        await onComplete({
            data_points: {
                appointments: JSON.stringify(resp),
                appointment_exists: resp.length > 0 ? 'true' : 'false',
            },
        });
    },
};
//# sourceMappingURL=findAppointments.js.map