import CONFIG from "../Core/сonfig.js";
import {createApi, fetchBaseQuery} from "@reduxjs/toolkit/query/react";


export const lensTypesApi = createApi({
    reducerPath: 'lensTypesApi',
    baseQuery: fetchBaseQuery({
        baseUrl: CONFIG.BASE_URL,
        prepareHeaders: (headers) => {
            const token = localStorage.getItem('access_token');
            if (token) headers.set('Authorization', `Bearer ${token}`);
            return headers;
        }
    }),
    endpoints: (builder) => ({
        getLensTypes: builder.query({
            query: () => `/lens_types/`,
        }),
    }),
});

export const {useGetLensTypesQuery} = lensTypesApi;