import { apiSlice } from '../api/apiSlice';

const filtersApi = apiSlice.injectEndpoints({
  endpoints: (builder) => ({
    getFilters: builder.query({
      query: () => `filters`,
      providesTags: ['Filters'],
    }),

    getFilter: builder.query({
      query: (id) => `filters/${id}`,
      providesTags: ['Filters'],
    }),

    addFilter: builder.mutation({
      query: (body) => ({
        url: `filters`,
        method: 'POST',
        body,
      }),
      invalidatesTags: ['Filters'],
    }),

    updateFilter: builder.mutation({
      query: ({ id, body }) => ({
        url: `filters/${id}`,
        method: 'PUT',
        body,
      }),
      invalidatesTags: ['Filters'],
    }),

    deleteFilter: builder.mutation({
      query: (id) => ({
        url: `filters/${id}`,
        method: 'DELETE',
      }),
      invalidatesTags: ['Filters'],
    }),
  }),
});

export const {
  useGetFiltersQuery,
  useGetFilterQuery,
  useAddFilterMutation,
  useUpdateFilterMutation,
  useDeleteFilterMutation,
} = filtersApi;
