import { Action, configureStore, ThunkAction } from "@reduxjs/toolkit";
import authReducer from "features/auth/authSlice";
import appErrorReducer from "features/error/appErrorSlice";
import localeReducer from "features/locale/localeSlice";
import orderSlice from "features/order/orderSlice";
import themeReducer from "features/theme/themeSlice";
import { baseApi } from "./api/apiSlice";

export const store = configureStore({
  reducer: {
    auth: authReducer,
    theme: themeReducer,
    locale: localeReducer,
    appError: appErrorReducer,
    order: orderSlice,
    [baseApi.reducerPath]: baseApi.reducer,
  },
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({ serializableCheck: false }).concat(
      baseApi.middleware
    ),
});

export type RootState = ReturnType<typeof store.getState>;

export type AppDispatch = typeof store.dispatch;

export type AppThunk<ReturnType = void> = ThunkAction<
  ReturnType,
  RootState,
  unknown,
  Action<string>
>;
