import { v4 } from "uuid";
import { p as prisma } from "./i18n-6Qq-kTth.js";
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;
  }
}
export {
  PaymentService
};
