'use client'

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

export const useCreatePaymentLink = () => {
  return useCustomMutation<ICreatePaymentLink, IBaseResponse<{ payment_link: IPaymentLink }>>(
    ['payment-links-create'],
    async data => {
      const res = await request<IBaseResponse<{ payment_link: IPaymentLink }>>({
        url: 'admin/payment/links',
        method: 'POST',
        data
      })

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