import { configureStore } from '@reduxjs/toolkit';
import { agentConfigSlice } from './slices/agent-config-slice';
import { runbookEditorSlice } from './slices/runbook-editor-slice';
import { permissionMatrixSlice } from './slices/permission-matrix-slice';
import { riskRulesSlice } from './slices/risk-rules.slice';
import { sessionReplaySlice } from './slices/session-replay.slice';
import { auditMiddleware } from './middleware/audit-middleware';

export function createStore() {
  return configureStore({
    reducer: {
      agentConfig: agentConfigSlice.reducer,
      runbookEditor: runbookEditorSlice.reducer,
      permissionMatrix: permissionMatrixSlice.reducer,
      riskRules: riskRulesSlice.reducer,
      sessionReplay: sessionReplaySlice.reducer,
    },
    middleware: (getDefaultMiddleware) =>
      getDefaultMiddleware().concat(auditMiddleware),
  });
}

export type AppStore = ReturnType<typeof createStore>;
export type RootState = ReturnType<AppStore['getState']>;
export type AppDispatch = AppStore['dispatch'];
