'use client'

import { IBaseResponse } from '@/@core/types/api'
import { useCustomMutation } from '@/hooks/api'
import { request } from '@/utils'
import { PAYMENT_LINKS_QUERY_KEY } from './useGetPaymentLinks'

export type DeletePaymentLinkPayload = {
  paymentLinkId: string
}

export const useDeletePaymentLink = () => {
  return useCustomMutation<DeletePaymentLinkPayload, IBaseResponse<null>>(
    ['payment-links-delete'],
    async payload => {
      const res = await request<IBaseResponse<null>>({
        url: `admin/payment/links/${payload.paymentLinkId}`,
        method: 'DELETE'
      })

      return res
    },
    {
      invalidateQueries: [PAYMENT_LINKS_QUERY_KEY]
    }
  )
}
