"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPharmacy = void 0;
const zod_1 = require("zod");
const extensions_core_1 = require("@awell-health/extensions-core");
const settings_1 = require("../../settings");
const client_1 = require("../../client");
const config_1 = require("./config");
exports.getPharmacy = {
    key: 'getPharmacy',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Get Pharmacy',
    description: "Retrieve a pharmacy profile using Elation's pharmacies API",
    fields: config_1.fields,
    previewable: 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 api = (0, client_1.makeAPIClient)(settings);
        const pharmacy = await api.getPharmacy(fields.ncpdpId.toString());
        await onComplete({
            data_points: {
                name: pharmacy.store_name,
                addressOne: pharmacy.address_line1,
                addressTwo: pharmacy.address_line2,
                city: pharmacy.city,
                state: pharmacy.state,
                zip: pharmacy.zip,
                phone: pharmacy.phone_primary,
                pharmacyObject: JSON.stringify(pharmacy),
            },
        });
    },
};
//# sourceMappingURL=getPharmacy.js.map