/* eslint-disable @typescript-eslint/no-explicit-any */
import { CaseReducer, PayloadAction } from "@reduxjs/toolkit"
import { ControllerContent, Page, Rule } from "./interface"


export const updateControllerListReducer: CaseReducer<
  ControllerContent,
  PayloadAction<ControllerContent>
> = (_, action) => {
  return action.payload
}

export const addControllerItemReducer: CaseReducer<
  ControllerContent,
  PayloadAction<ControllerContent>
> = (state, action) => {
  state = { ...action.payload, ...state }
  return state
}

export const setResourceRulesReducer: CaseReducer<
  ControllerContent,
  PayloadAction<Rule[]>
> = (state, action) => {
  state.rules = action.payload
}
export const setResourcePagesReducer: CaseReducer<
  ControllerContent,
  PayloadAction<Page[]>
> = (state, action) => {
  state.pages = action.payload
}
export const addResourceRulesInController: CaseReducer<
  ControllerContent,
  PayloadAction<Rule>
> = (state, action) => {
  state.rules.push(action.payload)
}

// export const removeControllerItemReducer: CaseReducer<
//   ControllerContent,
//   PayloadAction<string>
// > = (state, action) => {
//   const index = state.findIndex((i) => {
//     return i.ControllerID === action.payload
//   })
//   if (index !== -1) {
//     state.splice(index, 1)
//   }
// }
