// store/variablesSlice.js
import { createSlice } from "@reduxjs/toolkit";

const initialState = {
  last20Messages: null,
  deviceName: null,
  mac1: null,
  ip: null,
  subnet: null,
  gateway: null,
  cplInternalTimestamp: null,
  ntp1: null,
  ntp2: null,
  ntp3: null,
  ntpTimezone: null,
  ntpActive: null,
  de: null,
  counter: null,
  flutter: null,
  kueOnline: [],
  kueID: [],
  kueIso: [],
  kuePSTmMinus96V: [],
  kueAlarm1: [],
  kueAlarm2: [],
  kueResidence: [],
  kueCableBreak: [],
  kueGroundFault: [],
  kueLimit1: null,
  kueLimit2Low: null,
  kueDelay1: null,
  kueLoopInterval: null,
  kueVersion: null,
  tdrAtten: null,
  tdrPulse: null,
  tdrSpeed: null,
  tdrAmp: null,
  tdrTrigger: null,
  tdrLocation: null,
  tdrActive: null,
  kueOverflow: null,
  tdrLast: null,
  appVersion: null,
};

const variablesSlice = createSlice({
  name: "variables",
  initialState,
  reducers: {
    setVariable(state, action) {
      const { key, value } = action.payload;
      state[key] = value;
    },
    setVariables(state, action) {
      Object.entries(action.payload).forEach(([key, value]) => {
        state[key] = value;
      });
    },
  },
});

export const { setVariable, setVariables, updateValues } =
  variablesSlice.actions;
export default variablesSlice.reducer;
