import { a as createDefaultInstallation } from "./installation-b0PLfNT5.js";
import { a as appConfig } from "./config-OAUIL-se.js";
import { v4 } from "uuid";
import { p as prisma } from "./orgDomains-eTg-cjth.js";
const handler = {
  appType: appConfig.type,
  variant: appConfig.variant,
  slug: appConfig.slug,
  supportsMultipleInstalls: false,
  handlerType: "add",
  createCredential: ({ appType, user, slug, teamId }) => 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 prisma.booking.findUnique({
        select: {
          uid: true,
          title: true
        },
        where: {
          id: bookingId
        }
      });
      if (booking === null) {
        throw new Error("Booking not found");
      }
      const uid = v4();
      console.log("CREATE payment");
      const paymentData = await 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 prisma.booking.findUnique({
        select: {
          uid: true,
          title: true
        },
        where: {
          id: bookingId
        }
      });
      if (booking === null) {
        throw new Error("Booking not found");
      }
      const uid = v4();
      const paymentData = await 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" }));
export {
  index$1 as api,
  index as lib
};
