"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSubscription = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const config_1 = require("./config");
const lib_1 = require("../../lib");
exports.createSubscription = {
    key: 'createSubscription',
    category: extensions_core_1.Category.BILLING,
    title: 'Create subscription',
    description: 'Create a subscription in Stripe',
    fields: config_1.fields,
    previewable: false,
    dataPoints: config_1.dataPoints,
    onActivityCreated: async (payload, onComplete, onError) => {
        const { fields: input, stripe, patient, pathway, activity, } = await (0, lib_1.validateAndCreateStripeSdk)({
            fieldsSchema: config_1.FieldsValidationSchema,
            payload,
        });
        const res = await stripe.subscriptions.create({
            customer: input.customer,
            items: [
                {
                    price: input.item,
                },
            ],
            payment_settings: {
                payment_method_types: ['card'],
            },
            metadata: {
                awellPatientId: patient.id,
                awellCareflowId: pathway.id,
                awellActivityId: activity.id,
            },
        });
        await onComplete({
            data_points: {
                subscriptionId: res.id,
            },
        });
    },
};
//# sourceMappingURL=createSubscription.js.map