"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.eventCreated = void 0;
const schema_1 = require("../schema");
const helpers_1 = require("../helpers");
const dataPoints = {
    eventId: {
        key: 'eventId',
        valueType: 'string',
    },
    eventTypeId: {
        key: 'eventTypeId',
        valueType: 'string',
    },
    inviteeEmail: {
        key: 'inviteeEmail',
        valueType: 'string',
    },
    inviteeFirstName: {
        key: 'inviteeFirstName',
        valueType: 'string',
    },
    inviteeLastName: {
        key: 'inviteeLastName',
        valueType: 'string',
    },
    inviteeName: {
        key: 'inviteeName',
        valueType: 'string',
    },
    inviteeStatus: {
        key: 'inviteeStatus',
        valueType: 'string',
    },
    inviteeTimezone: {
        key: 'inviteeTimezone',
        valueType: 'string',
    },
    hostEmail: {
        key: 'hostEmail',
        valueType: 'string',
    },
    startTime: {
        key: 'startTime',
        valueType: 'date',
    },
    endTime: {
        key: 'endTime',
        valueType: 'date',
    },
    cancelUrl: {
        key: 'cancelUrl',
        valueType: 'string',
    },
    rescheduleUrl: {
        key: 'rescheduleUrl',
        valueType: 'string',
    },
    videoCallUrl: {
        key: 'videoCallUrl',
        valueType: 'string',
    },
    eventName: {
        key: 'eventName',
        valueType: 'string',
    },
    inviteePhoneNumber: {
        key: 'inviteePhoneNumber',
        valueType: 'string',
    },
    rescheduled: {
        key: 'rescheduled',
        valueType: 'boolean',
    },
    is_rescheduled_event: {
        key: 'is_rescheduled_event',
        valueType: 'boolean',
    },
};
exports.eventCreated = {
    key: 'eventCreated',
    dataPoints,
    onWebhookReceived: async ({ payload }, onSuccess, onError) => {
        var _a;
        const { payload: { email, first_name, last_name, name, scheduled_event, status, timezone, cancel_url, reschedule_url, old_invitee, rescheduled, text_reminder_number, }, } = schema_1.activeSchema.parse(payload);
        const scheduledEventId = (0, helpers_1.extractScheduledEventId)(scheduled_event);
        const scheduledEventTypeId = (0, helpers_1.extractScheduledEventTypeId)(scheduled_event);
        const hostEmail = (0, helpers_1.extractHostEmail)(scheduled_event);
        await onSuccess({
            data_points: {
                eventId: scheduledEventId,
                eventTypeId: scheduledEventTypeId,
                inviteeEmail: email,
                inviteeFirstName: first_name !== null && first_name !== void 0 ? first_name : '',
                inviteeLastName: last_name !== null && last_name !== void 0 ? last_name : '',
                inviteeName: name,
                inviteeStatus: status,
                inviteeTimezone: timezone,
                startTime: scheduled_event.start_time,
                endTime: scheduled_event.end_time,
                cancelUrl: cancel_url,
                rescheduleUrl: reschedule_url,
                hostEmail,
                videoCallUrl: (_a = scheduled_event.location.join_url) !== null && _a !== void 0 ? _a : '',
                inviteePhoneNumber: text_reminder_number !== null && text_reminder_number !== void 0 ? text_reminder_number : '',
                eventName: scheduled_event.name,
                rescheduled: String(rescheduled),
                is_rescheduled_event: String(old_invitee !== null),
            },
        });
    },
};
//# sourceMappingURL=eventCreated.js.map