import {createApi} from '@reduxjs/toolkit/query/react';
import {baseQueryWithAuth} from "./baseQuery.js";

export const setContentApi = createApi({
    reducerPath: 'setContentApi',
    baseQuery: baseQueryWithAuth,
    tagTypes: ['SetContent'],
    endpoints: (builder) => ({
        getSetContent: builder.query({
            query: (setId) => `/set_content/${setId}/`,
            providesTags: ['SetContent'],
        }),
        addSetContent: builder.mutation({
            query: ({setId, setContent}) => ({
                url: `/set_content/${setId}/`,
                method: 'POST',
                body: setContent
            }),
            invalidatesTags: ['SetContent']
        }),
        updateSetContent: builder.mutation({
            query: ({setId, setContent}) => ({
                url: `/set_content/${setId}/`,
                method: 'PUT',
                body: setContent
            }),
            invalidatesTags: ['SetContent']
        }),
    }),
});

export const {
    useGetSetContentQuery,
    useAddSetContentMutation,
    useUpdateSetContentMutation,
} = setContentApi;