import { $get, $post, $del, $patch, $put } from "@/plugins/axios";

// login
export const login = datas => {
  return $post("/api/login", datas);
};
export const logout = () => {
  return $del("/api/logout");
};
export const resetPwd = ({ userId, password }) => {
  return $patch(`/api/${userId}/password`, { password }, "json");
};

// work-manage
export const workList = () => {
  return $get("/api/admin/works");
};
export const workDetail = workId => {
  return $get(`/api/admin/works/${workId}`);
};
export const updateWork = datas => {
  return $put(`/api/admin/works/${datas.id}`, datas, "json");
};
export const createWork = datas => {
  return $post("/api/admin/works", datas, "json");
};
export const activeWork = workId => {
  return $patch(`/api/admin/works/${workId}`, {});
};
export const deleteWork = workId => {
  return $del(`/api/admin/works/${workId}`);
};

// work-overview
export const workOverviewDetail = workId => {
  return $get(`/api/admin/works/${workId}/overview`);
};

// paper-manage
export const paperPageList = datas => {
  return $get("/api/papers/listByQuestion", datas);
};
export const rotatePaper = (imageId, degree) => {
  return $get(`/api/images/${imageId}/rotate`, { degree });
};
export const absentPaper = imageId => {
  return $post(`/api/score/missing/${imageId}`, {});
};

// client-monitor
export const clientMonitorList = datas => {
  return $get("/api/marklog/equipmentMonitor", datas);
};

// student-manage
export const studentPageList = datas => {
  // TODO:考区-学校-考场 联动查询
  return $get("/api/students", datas);
};
export const updateStudent = datas => {
  // TODO:考区-学校-考场 联动查询
  if (datas.id) {
    return $put(`/api/students/${datas.id}`, datas);
  } else {
    return $post(`/api/students`, datas);
  }
};
export const deleteStudent = studentId => {
  return $del(`/api/students/${studentId}`, {});
};

// client-set -------------------------->
// client-user-set
export const clientUserPageList = datas => {
  return $get("/api/admin/users/collect", datas);
};
export const updateClientUser = datas => {
  if (datas.id) {
    return $put(`/api/admin/users/collect/${datas.id}`, datas, "json");
  } else {
    return $post("/api/admin/users/collect", datas, "json");
  }
};
export const deleteClientUser = userId => {
  return $del(`/api/admin/users/collect/${userId}`, {});
};
// inspection-user-set
export const inspectionUserPageList = () => {
  return $get("/api/admin/users/inspection");
};
export const deleteInspectionUser = userId => {
  return $del(`/api/admin/users/collect/${userId}`, {});
};
// client-param-set -------------------------->
// subject-set
export const subjectList = workId => {
  return $get(`/api/marksubjects/${workId}/subjects`);
};
export const subjectDetail = subjectId => {
  return $get(`/api/marksubjects/${subjectId}`);
};
export const updateSubject = datas => {
  if (datas.id) {
    return $post(`/api/marksubjects/${datas.id}/updateName`, datas);
  } else {
    return $post(`/api/marksubjects/${datas.id}`, datas);
  }
};
export const enableSubject = subjectId => {
  return $post(`/api/marksubjects/${subjectId}/updateEnable`, {});
};
// param-set
export const getParamsSet = workId => {
  return $get("/api/param/getParam", { workId });
};
export const updateCollectParams = datas => {
  return $post("/api/param/collect", datas);
};

// grading-set -------------------------->
// grading-level-set
// TO workDetail and updateWork

// grading-rule-set
export const updateLevelParams = datas => {
  return $post("/api/param/level", datas);
};
// update-paper
// grading-rule-set
export const updatePaperDetail = () => {
  // TODO:获取试卷上传状态
  return Promise.resolve({});
  // return $get(`/api/admin/works/${workId}`, {});
};

// mark-set -------------------------->
// mark-rule-set
export const updateScoreParams = datas => {
  return $post("/api/param/score", datas, "json");
};

// quality-analysis -------------------------->
// 档位占比
export const levelsPropReport = datas => {
  return $get("/api/quality/levelsPropReport", datas);
};
// 差值和
export const distanceReport = datas => {
  return $get("/api/quality/distanceReport", datas);
};
// 打回次数
export const callbackReport = datas => {
  return $get("/api/quality/callbackReport", datas);
};

// student-score -------------------------->
export const studentScoreList = datas => {
  return $get(`/api/papers/studentScore`, datas);
};

// grading -------------------------->
// grading-user-manage
export const gradingUserList = datas => {
  return $get("/api/admin/users", datas);
};
export const updateGradingUser = datas => {
  if (datas.id) {
    return $put(`/api/admin/users/${datas.id}`, datas, "json");
  } else {
    return $post("/api/admin/users", datas, "json");
  }
};
export const deleteGradingUser = userId => {
  return $del(`/api/admin/users/${userId}`);
};
// grading-group-manage
export const gradingGroupList = subjectId => {
  return $get(`/api/marksubjects/${subjectId}/markergroups`, {});
};
export const updateGradingGroup = (subjectId, datas) => {
  if (datas.groupId) {
    return $patch(
      `/api/marksubjects/${subjectId}/markergroups/${datas.groupId}`,
      datas,
      "json"
    );
  } else {
    return $post(`/api/marksubjects/${subjectId}/markergroups`, datas, "json");
  }
};
export const deleteGradingGroup = (subjectId, groupId) => {
  return $del(`/api/marksubjects/${subjectId}/markergroups/${groupId}`);
};
export const markUserList = ({ workId, subjectId }) => {
  return $get("/api/markers", { workId, subject: subjectId });
};
// grading-progress
export const gradingProgressDetail = ({ workId, subject }) => {
  return $get("/api/markers/stat/progress", { workId, subject });
};
export const areaStatProgress = subjectId => {
  return $get(`/api/marksubjects/${subjectId}/areaProgress`);
};
export const createTryGradingTask = datas => {
  // workId, subject
  return $get(`/api/trial/startTrial`, datas);
};
export const finishTryGradingTask = datas => {
  // workId, subject
  return $get(`/api/trial/finishTrial`, datas);
};
// grade-task
export const checkMissionStatus = ({ workId, subject }) => {
  return $get("/api/trial/checkMissionStatus", { workId, subject });
};
export const createGradingTask = ({ subjectId, taskCount, questionId }) => {
  return $patch(`/api/marksubjects/${subjectId}`, { taskCount, questionId });
};

// grading-detail
// level relate
export const workLevelList = workId => {
  return $get(`/api/admin/works/${workId}/levels`);
};
export const levelStatData = (subjectId, questionId) => {
  return $get(`/api/marksubjects/${subjectId}/stat/levels`, { questionId });
};
export const markerLevelStatData = (userId, questionId) => {
  return $get(`/api/markers/${userId}/stat/levels`, { questionId });
};
// area
export const areaList = ({ workId, subject }) => {
  return $get("/api/questions", { workId, subject });
};
// papers
export const paperList = datas => {
  // ?questionId=64&level=A&page=0&size=6&sort=secretNumber&isSample=true
  return $get("/api/papers", datas);
};
export const markerPaperList = datas => {
  // ?stage=LEVEL&markerId=49&size=6&page=0&sort=updatedOn,desc&questionId=73&isSample=false&level=C
  return $get("/api/marktasks", datas);
};
// grading or scoring
export const paperSelectLevel = (paperId, level, stage) => {
  return $patch(`/api/marktasks/${paperId}`, { stage, result: level }, "json");
};
export const paperPassLevel = paperId => {
  return $post(`/api/marktasks/${paperId}/skip`, {});
};
// grade or mark history
export const markHistoryList = (paperId, stage) => {
  return $get(`/api/papers/${paperId}/marktasks`, { stage });
};
// marker-status-info
export const markerDetail = userId => {
  return $get(`/api/markers/${userId}`);
};
// leader mark paper
export const leaderGradingPaper = (paperId, datas) => {
  // datas:{value: ,level:,range?}
  return $patch(`/api/papers/${paperId}`, datas, "json");
};
// review action history
export const actionHistory = datas => {
  return $get("/api/marktasks/reviewPaper", datas);
};
// sn search
export const taskSnSearch = (type, code, questionId) => {
  if (type === "task") {
    return $get(`/api/papers/search/byTaskSecretNumber`, {
      sn: code,
      questionId
    });
  } else {
    const paramName = type === "examNumber" ? "examNumber" : "sn";
    return $get(`/api/papers/one`, { [paramName]: code, questionId });
  }
};

// mark -------------------------->
// mark-progress
export const markProgressDetail = subjectId => {
  // TODO:
  return $get(`/api/marksubjects/${subjectId}/markergroups`, {});
};

// mark-task-manage
export const markTaskInfo = subjectId => {
  // TODO:
  return $get(`/api/marksubjects/${subjectId}/markergroups`, {});
};
export const createMarkTask = (subjectId, datas) => {
  // TODO:
  return $post(`/api/marksubjects/${subjectId}/markergroups`, datas);
};

// inspection -------------------------->
// inspection-log
export const inspectionActionLogPageList = datas => {
  // TODO:
  return $get(`/api/marklog/selectMarkLog`, datas);
};
export const inspectionCollectLogPageList = datas => {
  // TODO:
  return $get(`/api/marklog/selectCollectMarkLog`, datas);
};
export const inspectionCheckGradePageList = datas => {
  // TODO:
  return $get(`/api/marklog/selectCollectMarkLog`, datas);
};
export const inspectionConfirmCheckGrade = datas => {
  // TODO:
  return $post(`/api/marklog/selectCollectMarkLog`, datas);
};
