'use client'

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

export type UpdatePaymentLinkPayload = {
  paymentLinkId: string
  data: IUpdatePaymentLink
}

export const useUpdatePaymentLink = () => {
  return useCustomMutation<UpdatePaymentLinkPayload, IBaseResponse<IPaymentLink>>(
    ['payment-links-update'],
    async payload => {
      const res = await request<IBaseResponse<IPaymentLink>>({
        url: `admin/payment/links/${payload.paymentLinkId}`,
        method: 'PUT',
        data: payload.data
      })

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