import {
  getReportReview,
  getTreeList,
  getSingleList,
  getTreeGraph
} from './service';

const Model = {
  namespace: 'allBugs',
  state: {
    reportReview:{},
    bugTreeList:[],
    bugSingleList:[],
    bugTreeNode:{},
    bugItemDetail:{},
    treeGraph:{}
  },
  effects: {
    //todo:获取bug总数，点赞、点踩总数
    * getReportReview({ payload }, { call, put }) {
      const {report_id,case_take_id} = payload;
      let res = yield call(getReportReview, report_id,case_take_id);
      yield put({
        type: 'saveReportReview',
        payload: res,
      });
    },

    //todo:获取bug树状列表
    * getTreeList({ payload }, { call, put }) {
      const {case_take_id,start,count,page,roleId} = payload;
      let res = yield call(getTreeList, case_take_id,start,count,page,roleId);
      yield put({
        type: 'saveBugTreeList',
        payload: res,
      });
    },

    //todo:获取bug单一状列表
    * getSingleList({ payload }, { call, put }) {
      const {case_take_id,start,count,page,roleId} = payload;
      let res = yield call(getSingleList, case_take_id,start,count,page,roleId);
      yield put({
        type: 'saveBugSingleList',
        payload: res,
      });
    },

    //todo:获取bug树状图
    * getTreeGraph({ payload }, { call, put }) {
      const {id} = payload;
      let res = yield call(getTreeGraph, id);
      yield put({
        type: 'saveTreeGraph',
        payload: res,
      });
      return res;
    },
  },
  reducers: {
    saveReportReview(state, { payload }) {
      return { ...state, reportReview: payload };
    },
    saveBugTreeList(state, { payload }) {
      return { ...state, bugTreeList: payload };
    },
    saveBugSingleList(state, { payload }) {
      return { ...state, bugSingleList: payload };
    },
    saveBugItemDetail(state, { payload }) {
      return { ...state, bugItemDetail: payload };
    },
    saveBugTreeNode(state, { payload }) {
      return { ...state, bugTreeNode: payload };
    },
    saveTreeGraph(state, { payload }) {
      return { ...state, treeGraph: payload };
    },
  }
};
export default Model;
