import { Action, configureStore, ThunkAction } from "@reduxjs/toolkit";
import { authService } from "../services/auth-service";
import { reservationService } from "../services/reservation-service";
import { adminService } from "../services/admin-service";
import { contactService } from "../services/contact-service";
import authReducer from "./authSlice";

export const store = configureStore({
  reducer: {
    auth: authReducer,
    [authService.reducerPath]: authService.reducer,
    [reservationService.reducerPath]: reservationService.reducer,
    [adminService.reducerPath]: adminService.reducer,
    [contactService.reducerPath]: contactService.reducer,
  },
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware().concat(
      authService.middleware,
      reservationService.middleware,
      adminService.middleware,
      contactService.middleware,
    ),
});

export type AppDispatch = typeof store.dispatch;
export type RootState = ReturnType<typeof store.getState>;
export type AppThunk<ReturnType = void> = ThunkAction<
  ReturnType,
  RootState,
  unknown,
  Action<string>
>;
