import buildQueryString from '../../utils/queryBuilder';
import { apiSlice } from '../api/apiSlice';

const searchApi = apiSlice.injectEndpoints({
  endpoints: (builder) => ({
    getSearchData: builder.query({
      query: ({ endpoint, query }) => {
        const queryString = buildQueryString(query);
        return `search/${endpoint}?${queryString}`;
      },
      providesTags: ['Products'],
    }),
  }),
});

export const { useGetSearchDataQuery } = searchApi;
