'use client'

import { useCustomQuery } from '@/hooks/api'
import { IBaseResponse } from '@/@core/types/api'
import { IProduct } from '@/types/data/simpleProduct/product.interface'
import { request } from '@/utils'

interface ICategory {
  id: string
  name_ar: string
  name_en: string
  description_ar: string
  description_en: string
  image: string
  sort_order: number
  is_active: boolean
}

interface ICategoryProductsResponse {
  category: ICategory
  products: IProduct[]
}

export const useGetProductsByCategory = (categoryId?: string) => {
  return useCustomQuery<IBaseResponse<ICategoryProductsResponse>>(
    ['products-by-category', categoryId],
    () => request({ url: `/products/category/${categoryId}` }),
    { enabled: !!categoryId }
  )
}
