'use client'

import { useCustomQuery } from '@/hooks/api'
import { request } from '@/utils'
import { CustomUseQueryOptions, IBaseResponse } from '@/@core/types/api'
import { IPaymentMethodDetails } from '@/types/data/payment-method'

export const PAYMENT_METHOD_DETAILS_QUERY_KEY = 'payment-method-details'

export const useGetPaymentMethodDetails = (
  paymentMethodId?: string,
  options?: CustomUseQueryOptions<IBaseResponse<IPaymentMethodDetails>>
) => {
  const queryKey = [PAYMENT_METHOD_DETAILS_QUERY_KEY, paymentMethodId]

  return useCustomQuery<IBaseResponse<IPaymentMethodDetails>>(
    queryKey,
    () =>
      request({
        url: `/payment-methods/${paymentMethodId}`
      }),
    {
      enabled: Boolean(paymentMethodId),
      ...options
    }
  )
}
