"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const installation = require("./installation-vR6TkoQ4.cjs");
const config = require("./config-ab7cBLXC.cjs");
const uuid = require("uuid");
const index$2 = require("./index-QSf6WJj0.cjs");
const handler = {
  appType: config.appConfig.type,
  variant: config.appConfig.variant,
  slug: config.appConfig.slug,
  supportsMultipleInstalls: false,
  handlerType: "add",
  createCredential: ({ appType, user, slug, teamId }) => installation.createDefaultInstallation({ appType, user, slug, key: {}, teamId })
};
const handler$1 = handler;
const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  add: handler$1
}, Symbol.toStringTag, { value: "Module" }));
class PaymentService {
  async create(payment, bookingId) {
    try {
      const booking = await index$2.prisma.booking.findUnique({
        select: {
          uid: true,
          title: true
        },
        where: {
          id: bookingId
        }
      });
      if (booking === null) {
        throw new Error("Booking not found");
      }
      const uid = uuid.v4();
      console.log("CREATE payment");
      const paymentData = await index$2.prisma.payment.create({
        data: {
          uid,
          app: {
            connect: {
              slug: "mock-payment-app"
            }
          },
          booking: {
            connect: {
              id: bookingId
            }
          },
          amount: payment.amount,
          externalId: uid,
          currency: payment.currency,
          data: {},
          fee: 0,
          refunded: false,
          success: false
        }
      });
      return paymentData;
    } catch (error) {
      console.error(error);
      throw new Error("Payment could not be created");
    }
  }
  async update() {
    throw new Error("Method not implemented.");
  }
  async refund() {
    throw new Error("Method not implemented.");
  }
  async collectCard(payment, bookingId, _bookerEmail, paymentOption) {
    try {
      const booking = await index$2.prisma.booking.findUnique({
        select: {
          uid: true,
          title: true
        },
        where: {
          id: bookingId
        }
      });
      if (booking === null) {
        throw new Error("Booking not found");
      }
      const uid = uuid.v4();
      const paymentData = await index$2.prisma.payment.create({
        data: {
          uid,
          app: {
            connect: {
              slug: "paypal"
            }
          },
          booking: {
            connect: {
              id: bookingId
            }
          },
          amount: payment.amount,
          currency: payment.currency,
          data: {},
          fee: 0,
          refunded: false,
          success: false,
          paymentOption,
          externalId: ""
        }
      });
      if (!paymentData) {
        throw new Error();
      }
      return paymentData;
    } catch (error) {
      console.error(error);
      throw new Error("Payment could not be created");
    }
  }
  chargeCard() {
    throw new Error("Method not implemented.");
  }
  getPaymentPaidStatus() {
    throw new Error("Method not implemented.");
  }
  getPaymentDetails() {
    throw new Error("Method not implemented.");
  }
  afterPayment() {
    return Promise.resolve();
  }
  deletePayment() {
    return Promise.resolve(false);
  }
  isSetupAlready() {
    return true;
  }
}
const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  PaymentService
}, Symbol.toStringTag, { value: "Module" }));
exports.api = index$1;
exports.lib = index;
