import { A5TableType } from "@/types";
import { A2Tab1Type, A2Tab2Type } from "@/types/api/A2Dict";

// 初始化状态
const initState = {
  // 项目属性的数据  职能，状态
  A2Tab1_1Obj: {
    status: [],
    job: [],
    main: [],
    dept: [],
    projectBusiness: [],
    projectScope: [],
    projectApp: [],
  } as A2Tab1Type,

  // 阶段
  A2Tab1_2Arr: [] as A5TableType[],

  // -------内控文件属性----------
  A2Tab2Arr: [] as A2Tab2Type[],
};

// 定义 action 类型
type Props =
  | { type: "A2/getInfo1_1"; payload: A2Tab1Type }
  | { type: "A2/getInfo1_2"; payload: A5TableType[] }
  | { type: "A2/getInfo2"; payload: A2Tab2Type[] };

// 频道 reducer
export default function A2Reducer(state = initState, action: Props) {
  switch (action.type) {
    // 项目属性的数据
    case "A2/getInfo1_1":
      return { ...state, A2Tab1_1Obj: action.payload };
    case "A2/getInfo1_2":
      return { ...state, A2Tab1_2Arr: action.payload };
    // 内控文件属性
    case "A2/getInfo2":
      return { ...state, A2Tab2Arr: action.payload };
    default:
      return state;
  }
}
