'use client'

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

export type CancelPaymentLinkPayload = {
  paymentLinkId: string
}

export const useCancelPaymentLink = () => {
  return useCustomMutation<CancelPaymentLinkPayload, IBaseResponse<IPaymentLink>>(
    ['payment-links-cancel'],
    async payload => {
      const res = await request<IBaseResponse<IPaymentLink>>({
        url: `admin/payment/links/${payload.paymentLinkId}/cancel`,
        method: 'POST'
      })

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