"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bookAppointment = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const extensions_core_2 = require("@awell-health/extensions-core");
const zod_1 = require("zod");
const zod_validation_error_1 = require("zod-validation-error");
const schema_1 = require("../../schema");
const config_1 = require("./config");
exports.bookAppointment = {
    key: 'bookAppointment',
    title: 'Book appointment',
    description: 'Enable a stakeholder to book an appointment via Cal.com.',
    category: extensions_core_2.Category.SCHEDULING,
    fields: config_1.fields,
    dataPoints: config_1.dataPoints,
    options: {
        stakeholders: {
            label: 'Stakeholder',
            mode: 'single',
        },
    },
    previewable: false, // We don't have Awell Hosted Pages in Preview so cannot be previewed.
    onActivityCreated: async (payload, onComplete, onError) => {
        try {
            (0, extensions_core_1.validate)({
                schema: zod_1.z.object({
                    settings: schema_1.SettingsSchema,
                    fields: config_1.FieldsValidationSchema,
                }),
                payload,
            });
        }
        catch (err) {
            if (err instanceof zod_1.ZodError) {
                const error = (0, zod_validation_error_1.fromZodError)(err);
                await onError({
                    events: [
                        {
                            date: new Date().toISOString(),
                            text: { en: error.message },
                            error: {
                                category: 'BAD_REQUEST',
                                message: error.message,
                            },
                        },
                    ],
                });
            }
        }
    },
};
//# sourceMappingURL=bookAppointment.js.map