// src/app/store.js
import { configureStore } from "@reduxjs/toolkit";
import authReducer from "../features/auth/authSlice";
import dashboardReducer from "../features/dashboard/dashboardSlice";

import { orderApi } from "../features/orders/ordersAPI";
import productApi from "../features/products/productAPI";
import { categoryApi } from "../features/categories/categoryAPI";
import { salesApi } from "../features/report/salesAPI";
import { customersApi } from "../features/report/customersAPI";
import { ordersApi } from "../features/report/ordersAPI";
import { inventoryApi } from "../features/report/inventoryAPI";
// import { couponApi } from "../features/coupons/couponSlice"; // ✅ FIXED
import { couponApi } from "../features/coupons/couponAPI";


export const store = configureStore({
  reducer: {
    auth: authReducer,
    dashboard: dashboardReducer,

    // RTK Query reducers
    [orderApi.reducerPath]: orderApi.reducer,
    [productApi.reducerPath]: productApi.reducer,
    [categoryApi.reducerPath]: categoryApi.reducer,
    [salesApi.reducerPath]: salesApi.reducer,
    [customersApi.reducerPath]: customersApi.reducer,
    [ordersApi.reducerPath]: ordersApi.reducer,
    [inventoryApi.reducerPath]: inventoryApi.reducer,
    [couponApi.reducerPath]: couponApi.reducer, // ✅ OK
  },

  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware().concat(
      orderApi.middleware,
      productApi.middleware,
      categoryApi.middleware,
      salesApi.middleware,
      customersApi.middleware,
      ordersApi.middleware,
      inventoryApi.middleware,
      couponApi.middleware // ✅ REQUIRED
    ),
});
