import { $postParam, $post } from "@/plugins/axios";

// user-manage
export const userListPage = (datas) => {
  return $postParam("/api/admin/sys/user/list_customer", datas);
};
export const updateUser = (datas) => {
  return $post("/api/admin/sys/user/save_customer", datas);
};
export const ableUser = ({ id, enable }) => {
  return $post("/api/admin/sys/user/enable", { id, enable });
};
export const resetPwd = (id) => {
  return $post("/api/admin/sys/user/reset_password", { id });
};
export const userRoleListPage = () => {
  return $postParam("/api/admin/sys/role/list_to_user", {});
};
export const adminRoleListPage = () => {
  return $postParam("/api/admin/sys/role/list_to_admin", {});
};
export const setRoleDefault = ({ id, defaultRole }) => {
  return $postParam("/api/admin/sys/role/builtin", { id, defaultRole });
};
// menu-manage
export const menuList = (datas) => {
  return $postParam("/api/admin/sys/privilege/list", datas);
};
export const updateMenu = (datas) => {
  return $post("/api/admin/sys/privilege/save", datas);
};
export const deleteMenu = (id) => {
  return $post("/api/admin/sys/privilege/remove", { id });
};

// auth-set
export const authSelect = () => {
  return $post("/api/admin/auth/select", {});
};
export const offlineActivation = (datas) => {
  return $post("/api/admin/auth/offline/activation", datas);
};
export const onlineActivation = (datas) => {
  return $postParam("/api/admin/auth/online/activation", datas);
};
export const exportDeviceInfo = () => {
  return $post(
    "/api/admin/auth/export/device/info",
    {},
    {
      responseType: "blob",
    }
  );
};
// school-manage
export const schoolList = () => {
  return $postParam("/api/admin/common/school/list", {});
};
export const schoolSync = () => {
  return $postParam("/api/admin/auth/sync/org", {});
};
export const updateSchool = (datas) => {
  let formData = new FormData();
  Object.keys(datas).forEach((k) => {
    formData.append(k, datas[k]);
  });
  return $post("/api/admin/common/school/update", formData);
};
// school-set
export const schoolSetCheckInfo = (schoolId) => {
  return $postParam("/api/admin/set/user/select", { schoolId });
};
export const schoolSetCheckUpdate = (datas) => {
  return $post("/api/admin/set/user/save", datas);
};
export const sysCustomMenuList = () => {
  return $postParam("/api/admin/set/menu/custom/list", {});
};
export const schoolSetMenuInfo = (schoolId) => {
  return $postParam("/api/admin/set/menu/custom/get_school_custom_privileges", {
    schoolId,
  });
};
export const schoolSetMenuUpdate = (datas) => {
  return $post("/api/admin/set/menu/custom/save", datas);
};

// 学号配置
export const schoolSetStdnoInfo = (schoolId) => {
  return $postParam("/api/admin/set/student_number_config/select", {
    schoolId,
  });
};
export const schoolSetStdnoUpdate = (datas) => {
  return $post("/api/admin/set/student_number_config/save", datas);
};

// 试卷规格配置
export const sysPaperSizeList = () => {
  return $postParam("/api/admin/set/paper/sys/select", {});
};
export const schoolSetPaperInfo = (schoolId) => {
  return $postParam("/api/admin/set/paper/select", {
    schoolId,
  });
};
export const schoolSetPaperUpdate = (datas) => {
  return $post("/api/admin/set/paper/save", datas);
};

// 角色配置
export const sysCustomRoleList = () => {
  return $postParam("/api/admin/set/role/custom/list", {});
};
export const schoolSetRoleInfo = (schoolId) => {
  return $postParam("/api/admin/set/role/custom/get_school_custom_roles", {
    schoolId,
  });
};
export const schoolSetRoleUpdate = (datas) => {
  return $post("/api/admin/set/role/custom/save", datas);
};
export const schoolSetSyncInfo = (schoolId) => {
  return $postParam("/api/admin/set/sync/select", {
    schoolId,
  });
};
export const schoolSetSyncUpdate = (datas) => {
  return $post("/api/admin/set/sync/save", datas);
};
export const schoolSetDataBackup = (schoolId) => {
  return $postParam("/api/admin/set/backup", { schoolId });
};

export const systemLogExport = () => {
  return $postParam(
    "/api/admin/common/log/download",
    {},
    {
      responseType: "blob",
    }
  );
};
// scan-log-manage
export const scanLogListPage = (datas) => {
  return $postParam("/api/scan/log/list", datas);
};
// course target
export const schoolSetCourseTargetQuery = (schoolId) => {
  return $postParam("/api/admin/set/course/degree/select", {
    schoolId,
  });
};
export const schoolSetCourseTargetSave = (datas) => {
  return $postParam("/api/admin/set/course/degree/save", datas);
};

// package-manage
export const packageInfo = () => {
  return $postParam("/api/admin/sys/client/package/external", {});
};
export const uploadPackage = (datas, config = {}) => {
  return $post("/api/admin/sys/client/package/upload", datas, config);
};

// tool-manage
export const toolInfo = () => {
  return $postParam("/api/admin/sys/tools/external", {
    type: "PICTURE_DOWNLOAD",
  });
};
export const uploadTool = (datas, config = {}) => {
  return $post("/api/admin/sys/tools/upload", datas, config);
};
