import { A4IpType, A4tableType } from '@/types'

// 初始化状态
const initState = {
  // 列表数据
  tableInfo: {
    list: [] as A4tableType[],
    total: 0
  },
  // ip列表数据
  ipList: [] as A4IpType[]
}

// 定义 action 类型
type Props =
  | {
      type: 'A4/getList'
      payload: { list: A4tableType[]; total: number }
    }
  | {
      type: 'A3/getIpList'
      payload: A4IpType[]
    }

// reducer
export default function Reducer(state = initState, action: Props) {
  switch (action.type) {
    // 获取列表数据
    case 'A4/getList':
      return { ...state, tableInfo: action.payload }

    case 'A3/getIpList':
      return { ...state, ipList: action.payload }

    default:
      return state
  }
}
