"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAppointment = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const extensions_core_2 = require("@awell-health/extensions-core");
const client_1 = require("../client");
const fields = {
    appointmentId: {
        id: 'appointmentId',
        label: 'Appointment ID',
        description: 'Provide the ID of the appointment you want to fetch the details of',
        type: extensions_core_1.FieldType.NUMERIC,
        required: true,
    },
};
const dataPoints = {
    scheduledDate: {
        key: 'scheduledDate',
        valueType: 'date',
    },
    reason: {
        key: 'reason',
        valueType: 'string',
    },
    patientId: {
        key: 'patientId',
        valueType: 'number',
    },
    physicianId: {
        key: 'physicianId',
        valueType: 'number',
    },
    practiceId: {
        key: 'practiceId',
        valueType: 'number',
    },
    duration: {
        key: 'duration',
        valueType: 'number',
    },
    description: {
        key: 'description',
        valueType: 'string',
    },
    serviceLocationId: {
        key: 'serviceLocationId',
        valueType: 'number',
    },
    telehealthDetails: {
        key: 'telehealthDetails',
        valueType: 'string',
    },
    status: {
        key: 'status',
        valueType: 'json',
    },
    statusString: {
        key: 'statusString',
        valueType: 'string',
    },
    appointment: {
        key: 'appointment',
        valueType: 'json',
    },
};
exports.getAppointment = {
    key: 'getAppointment',
    category: extensions_core_2.Category.EHR_INTEGRATIONS,
    title: 'Get Appointment',
    description: "Retrieve an appointment using Elation's scheduling API.",
    fields,
    previewable: true,
    supports_automated_retries: true,
    dataPoints,
    onActivityCreated: async (payload, onComplete, onError) => {
        var _a, _b;
        const appointmentId = extensions_core_1.NumericIdSchema.parse(payload.fields.appointmentId);
        // API Call should produce AuthError or something dif.
        const api = (0, client_1.makeAPIClient)(payload.settings);
        const appointment = await api.getAppointment(appointmentId);
        await onComplete({
            data_points: {
                scheduledDate: appointment.scheduled_date,
                reason: appointment.reason,
                patientId: String(appointment.patient),
                physicianId: String(appointment.physician),
                practiceId: String(appointment.practice),
                duration: String(appointment.duration),
                description: appointment.description,
                serviceLocationId: String((_a = appointment.service_location) === null || _a === void 0 ? void 0 : _a.id),
                telehealthDetails: appointment.telehealth_details,
                status: JSON.stringify(appointment.status),
                statusString: (_b = appointment.status) === null || _b === void 0 ? void 0 : _b.status,
                appointment: JSON.stringify(appointment),
            },
        });
    },
};
//# sourceMappingURL=getAppointment.js.map