// /redux/slices/systemVoltTempSlice.ts
import { createSlice, PayloadAction } from "@reduxjs/toolkit";

interface VoltagesState {
  voltages: { [key: string]: number };
  history: { time: number; [key: string]: number }[];
}

const initialState: VoltagesState = {
  voltages: {
    "+5V": 0,
    "+15V": 0,
    "-15V": 0,
    "-98V": 0,
    "ADC Temp": 0,
    "CPU Temp": 0,
  },
  history: [],
};

const systemVoltTempSlice = createSlice({
  name: "systemVoltTemp",
  initialState,
  reducers: {
    setVoltages(state, action: PayloadAction<{ [key: string]: number }>) {
      state.voltages = action.payload;
    },
    addHistory(
      state,
      action: PayloadAction<{ time: number; [key: string]: number }>
    ) {
      state.history.push(action.payload);
    },
  },
});

export const { setVoltages, addHistory } = systemVoltTempSlice.actions;
export default systemVoltTempSlice.reducer;
