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

interface TDRDataState {
  dataById: {
    [id: number]: { d: number; p: number }[];
  };
  selectedId: number | null;
}

const initialState: TDRDataState = {
  dataById: {},
  selectedId: null,
};

const tdrDataByIdSlice = createSlice({
  name: "tdrDataById",
  initialState,
  reducers: {
    setTDRChartDataById: (
      state,
      action: PayloadAction<{ id: number; data: { d: number; p: number }[] }>
    ) => {
      state.dataById[action.payload.id] = action.payload.data;
    },
    setSelectedTDRId: (state, action: PayloadAction<number>) => {
      state.selectedId = action.payload;
    },
  },
});

export const { setTDRChartDataById, setSelectedTDRId } =
  tdrDataByIdSlice.actions;
export default tdrDataByIdSlice.reducer;
