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

export const appointmentTypesApi = createApi({
    reducerPath: 'appointmentTypesApi',
    baseQuery: fetchBaseQuery({
        baseUrl: CONFIG.BASE_URL,
        prepareHeaders: (headers) => {
            const token = localStorage.getItem('access_token');
            if (token) headers.set('Authorization', `Bearer ${token}`);
            return headers;
        }
    }),
    tagsTypes: ['AppointmentTypes'],
    endpoints: (builder) => ({
        getAppointmentTypes: builder.query({
            query: () => '/appointment_types/',
            providesTags: ['AppointmentTypes'],
        }),
    }),
});

export const {useGetAppointmentTypesQuery} = appointmentTypesApi;