import { HomeSortType, HomeModelType, modelItem } from "@/types";

// 初始化状态应用注解
const initState = {
  sortList: [] as HomeSortType[],
  ageList: [] as HomeSortType[],
  modelInfo: {} as HomeModelType,
  qrModel: {} as modelItem,
};

type HomeActionType =
  | { type: "home/setSort"; payload: HomeSortType[] }
  | { type: "home/setAge"; payload: HomeSortType[] }
  | { type: "home/setList"; payload: HomeModelType }
  | { type: "home/Model"; payload: modelItem };

// 频道 reducer
export default function loginReducer(
  state = initState,
  action: HomeActionType
) {
  switch (action.type) {
    case "home/setSort":
      return { ...state, sortList: action.payload };
    case "home/setAge":
      return { ...state, ageList: action.payload };
    case "home/setList":
      return { ...state, modelInfo: action.payload };
    case "home/Model":
      return { ...state, qrModel: action.payload };
    default:
      return state;
  }
}
