// /redux/store.ts
import { configureStore } from "@reduxjs/toolkit";
import authReducer from "./slices/authSlice";
import kueChartModeReducer from "./slices/kueChartModeSlice";
import webVersionReducer from "./slices/webVersionSlice";
import kabelueberwachungChartReducer from "./slices/kabelueberwachungChartSlice";
import last20MessagesReducer from "./slices/last20MessagesSlice";
import systemSettingsReducer from "./slices/systemSettingsSlice";
import opcuaSettingsReducer from "./slices/opcuaSettingsSlice";
import digitalOutputsReducer from "./slices/digitalOutputsSlice";
import brushReducer from "./slices/brushSlice";
import tdrChartReducer from "./slices/tdrChartSlice";
import analogInputsSlice from "./slices/analogInputs/analogInputsSlice";
import digitalInputsReducer from "./slices/digitalInputsSlice";
import tdrReferenceChartReducer from "./slices/tdrReferenceChartSlice";
import loopChartReducer from "./slices/loopChartSlice";
import tdmChartReducer from "./slices/tdmChartSlice";
import tdrDataByIdReducer from "./slices/tdrDataByIdSlice";
import kueDataReducer from "./slices/kueDataSlice";
import selectedChartDataReducer from "./slices/selectedChartDataSlice";
import tdmSingleChartReducer from "./slices/tdmSingleChartSlice";
import tdrReferenceChartDataBySlotReducer from "./slices/tdrReferenceChartDataBySlotSlice";
import loopChartTypeSlice from "./slices/loopChartTypeSlice";
import systemVoltTempReducer from "./slices/systemVoltTempSlice";
import analogInputsHistoryReducer from "./slices/analogInputs/analogInputsHistorySlice";
import selectedAnalogInputReducer from "./slices/analogInputs/selectedAnalogInputSlice";
import messagesReducer from "./slices/messagesSlice";
import firmwareUpdateReducer from "@/redux/slices/firmwareUpdateSlice";
import confirmModalReducer from "./slices/confirmModalSlice";
import firmwareProgressReducer from "./slices/firmwareProgressSlice";
import systemspannung5VplusReducer from "./slices/systemspannung5VplusSlice";
import systemspannung15VminusReducer from "./slices/systemspannung15VminusSlice";
import systemspannung15VplusReducer from "./slices/systemspannung15VplusSlice";
import systemspannung98VminusReducer from "./slices/systemspannung98VminusSlice";
import temperaturAdWandlerReducer from "./slices/temperaturAdWandlerSlice";
import temperaturProzessorReducer from "./slices/temperaturProzessorSlice";
import { combineReducers } from "@reduxjs/toolkit";
import { useDispatch, useSelector, TypedUseSelectorHook } from "react-redux";
import systemChartReducer from "./slices/systemChartSlice";
import analogInputsUiReducer from "./slices/analogInputs/analogInputsUiSlice";
import dateRangePickerReducer from "./slices/dateRangePickerSlice";
import deviceEventsReducer from "./slices/deviceEventsSlice";

const rootReducer = combineReducers({
  systemspannung5Vplus: systemspannung5VplusReducer,
  systemspannung15Vplus: systemspannung15VplusReducer,
  systemspannung15Vminus: systemspannung15VminusReducer,
  systemspannung98Vminus: systemspannung98VminusReducer,
  temperaturAdWandler: temperaturAdWandlerReducer,
  temperaturProzessor: temperaturProzessorReducer,
  authSlice: authReducer,
  kueChartModeSlice: kueChartModeReducer,
  webVersionSlice: webVersionReducer,
  digitalInputsSlice: digitalInputsReducer,
  kabelueberwachungChartSlice: kabelueberwachungChartReducer,
  last20MessagesSlice: last20MessagesReducer,
  systemSettingsSlice: systemSettingsReducer,
  opcuaSettingsSlice: opcuaSettingsReducer,
  digitalOutputsSlice: digitalOutputsReducer,
  brushSlice: brushReducer,
  tdrChartSlice: tdrChartReducer,
  tdrReferenceChartSlice: tdrReferenceChartReducer,
  loopChartSlice: loopChartReducer,
  tdmChartSlice: tdmChartReducer,
  tdrDataByIdSlice: tdrDataByIdReducer,
  kueDataSlice: kueDataReducer,
  selectedChartDataSlice: selectedChartDataReducer,
  tdmSingleChartSlice: tdmSingleChartReducer,
  tdrReferenceChartDataBySlotSlice: tdrReferenceChartDataBySlotReducer,
  loopChartType: loopChartTypeSlice,
  systemVoltTemp: systemVoltTempReducer,
  messages: messagesReducer,
  firmwareUpdate: firmwareUpdateReducer,
  confirmModal: confirmModalReducer,
  firmwareProgress: firmwareProgressReducer,
  systemChartSlice: systemChartReducer,
  analogInputs: analogInputsSlice,
  analogInputsHistory: analogInputsHistoryReducer,
  selectedAnalogInput: selectedAnalogInputReducer,
  analogInputsUi: analogInputsUiReducer,
  dateRangePicker: dateRangePickerReducer,
  deviceEvents: deviceEventsReducer,
});
// ⬆️ Alle deine Imports und combineReducers bleiben so wie du sie geschrieben hast ...

// ✅ Store erstellen
export const store = configureStore({
  reducer: rootReducer,
  // (optional) middleware anpassen, z. B. um Warnungen zu ignorieren:
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({
      serializableCheck: false, // z. B. falls du redux-persist nutzt oder dispatch mit non-serializable Payloads hast
    }),
});

// ✅ Typen für AppDispatch & RootState
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;

// ✅ Hooks für Typsicherheit
export const useAppDispatch = () => useDispatch<AppDispatch>();
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
