export default function usePaymentMethod() {
  function linkEWallet({
    type = "GCASH",
    customer_id = "",
    success_return_url = "",
    failure_return_url = "",
    cancel_return_url = "",
    category = "individual",
  } = {}) {
    return useNuxtApp().$api<Record<string, any>>(
      "/api/payment-methods/e-wallet",
      {
        method: "POST",
        body: {
          customer_id,
          type,
          success_return_url,
          failure_return_url,
          cancel_return_url,
          category,
        },
      }
    );
  }

  function linkCard({
    cardType = "",
    cardNumber = "",
    expiryMonth = "",
    expiryYear = "",
    cvv = "",
    cardholderName = "",
    currency = "",
    success_return_url = "",
    failure_return_url = "",
    subscriptionData = {},
  } = {}) {
    return useNuxtApp().$api<Record<string, any>>("/api/payment-methods/card", {
      method: "POST",
      body: {
        cardType,
        cardNumber,
        expiryMonth,
        expiryYear,
        cvv,
        cardholderName,
        currency,
        success_return_url,
        failure_return_url,
        subscriptionData,
      },
    });
  }

  function getByUser(user = "") {
    return useNuxtApp().$api<Array<Record<string, any>>>(
      `/api/payment-methods/user/${user}`,
      {
        method: "GET",
      }
    );
  }

  function getByOrg(org = "") {
    return useNuxtApp().$api<Array<Record<string, any>>>(
      `/api/payment-methods/org/${org}`,
      {
        method: "GET",
      }
    );
  }

  const eWalletNumber = useState("eWalletNumber", () => "");
  const cardNumber = useState("cardNumber", () => "");
  const cardExpiration = useState("cardExpiration", () => "");
  const cardSecurityCode = useState("cardSecurityCode", () => "");
  const cardholderName = useState("cardholderName", () => "");
  const selectedPaymentMethod = useState("selectedPaymentMethod", () => "");

  function reset() {
    eWalletNumber.value = "";
    cardNumber.value = "";
    cardExpiration.value = "";
    cardSecurityCode.value = "";
    cardholderName.value = "";
  }

  return {
    linkEWallet,
    linkCard,
    getByUser,
    getByOrg,
    eWalletNumber,
    cardNumber,
    cardExpiration,
    cardSecurityCode,
    cardholderName,
    selectedPaymentMethod,
    reset,
  };
}
