'use client'

import type { IBaseResponse } from '@/@core/types/api'
import { request } from '@/utils'
import { useCustomMutation } from '@/hooks/api'

export type ValidateCouponPayload = {
  code: string
  phone?: string
  order_amount?: number
  items?: Array<{
    product_id: string
    price: number
    quantity: number
  }>
}

export interface ValidateCouponResponse {
  coupon?: Record<string, any>
  discount_amount?: number
  final_amount?: number
}

export const useValidateCoupon = () => {
  return useCustomMutation<ValidateCouponPayload, IBaseResponse<ValidateCouponResponse>>(
    ['orders-validate-coupon'],
    payload =>
      request({
        url: '/coupons/validate',
        method: 'POST',
        data: payload,
        withToken: false
      })
  )
}
