import { useMutation, useQuery } from "@tanstack/react-query";
import * as api from "../service/BrandService";
import { useSharedStore } from "@/shared/store/sharedStore";

export const useGetBrands = (page: number = 1, limit: number = 10) => {
  const { search } = useSharedStore();
  return useQuery({
    queryKey: ["brands", page, limit, search],
    queryFn: () => api.getBrands(page, limit, search),
  });
};

export const useDeleteBrand = () => {
  return useMutation({
    mutationFn: (id: string) => api.deleteBrand(id),
  });
};

export const useCreateBrand = () => {
  return useMutation({
    mutationFn: api.createBrand,
  });
};

export const useUpdateBrand = () => {
  return useMutation({
    mutationFn: api.updateBrand,
  });
};

export const useGetBrandById = (id: string) => {
  return useQuery({
    queryKey: ["brand", id],
    queryFn: () => api.getBrandById(id),
  });
};
