import {
  IManageDeptMaterialItem,
  IManageAssessmentIndex,
  IManageDeptItem,
  IManageFormDetail,
  IManageFormItem,
  IManageFormListParams,
  IManageIndexDetail,
  IManageUserItem,
  PUBLISH_ENUM,
  ASS_INDEX_TYPE,
  IManageDeptAllocationOfIndexItem,
  IManageRoleGroupItem,
  IManageAssOperationResponse,
  IAssIndexDetail,
  ISaveManageFileParams,
  YES_OR_NO,
  IManageNormItem,
  MaterialType,
  DEPT_STATUS_ENUM,
  REVIEW_MATERIAL_TYPE,
  ARCHIVE_TYPE,
} from "@/types";
import { requestByGet, requestByPost, requestPagination } from "@dage/service";

export const getManageIndexListApi = (params: any) => {
  return requestByPost("/api/cms/assess/pageList", params);
};

export const saveManageIndexApi = (params: any) => {
  return requestByPost("/api/cms/assess/save", params);
};

export const deleteManageIndexApi = (ids: string | number) => {
  return requestByGet(`/api/cms/assess/removes/${ids}`);
};

export const getManageIndexDetailApi = (id: string | number) => {
  return requestByGet<IManageIndexDetail>(`/api/cms/assess/detail/${id}`);
};

export const publishManageIndexApi = (
  id: string | number,
  status = PUBLISH_ENUM.PUBLISHED
) => {
  return requestByGet(`/api/cms/assess/publish/${id}/${status}`);
};

export const getManageRoleDeptListApi = (id: number | string) => {
  return requestByGet<IManageDeptItem[]>(`/api/cms/dept/getList/${id}`);
};

export const getManageUserListApi = () => {
  return requestByGet<IManageUserItem[]>("/api/cms/dept/getUser");
};

export const saveManageRoleDeptApi = (params: any) => {
  return requestByPost("/api/cms/dept/save", params);
};

export const deleteManageRoleDeptApi = (ids: number | string) => {
  return requestByGet(`/api/cms/dept/removes/${ids}`);
};

export const getManageAssFixedListApi = (
  id: number | string,
  searchKey?: string
) => {
  return requestByGet<IManageAssessmentIndex[]>(
    `/api/cms/assessFixed/getList/${id}`,
    {
      searchKey,
    }
  );
};

export const getManageAssOperationListApi = (
  id: number | string,
  searchKey?: string
) => {
  return requestByGet<IManageAssOperationResponse>(
    `/api/cms/assessOperation/getList/${id}`,
    {
      searchKey,
    }
  );
};

export const setManageAssFixedApi = (
  id: string | number,
  indexIds: string[]
) => {
  return requestByPost(`/api/cms/assessFixed/save/${id}`, indexIds);
};

export const setManageAssOperationApi = (
  id: string | number,
  indexIds: string[]
) => {
  return requestByPost(`/api/cms/assessOperation/save/${id}`, indexIds);
};

export const getManageFormListApi = (params: IManageFormListParams) => {
  return requestPagination<IManageFormItem>("/api/cms/fill/pageList", params);
};

// 部门考核单概况
export const getManageFormDetailApi = (
  id: number | string,
  assessId: number | string
) => {
  return requestByGet<IManageFormDetail>(
    `/api/cms/fill/detail/${id}/${assessId}`
  );
};

export const getManageEvaluationListApi = (params: IManageFormListParams) => {
  return requestPagination<IManageFormItem>("/api/cms/review/pageList", params);
};

export const getManageEvaluationDetailApi = (id: number | string) => {
  return requestByGet<IManageFormDetail>(`/api/cms/review/detail/${id}`);
};

export const getManageDeptAllocationOfDataListApi = (id: number | string) => {
  return requestByGet<null | IManageDeptMaterialItem[]>(
    `/api/cms/dept/material/getList/${id}`
  );
};

export const saveManageDeptAllocationOfDataApi = (params: any) => {
  return requestByPost("/api/cms/dept/material/save", params);
};

export const getManageDeptAllocationOfIndexListApi = (
  assessId: number | string,
  deptId: number | string,
  normType: ASS_INDEX_TYPE,
  // 查看未分配
  assign?: number
) => {
  return requestByGet<IManageDeptAllocationOfIndexItem[]>(
    `/api/cms/dept/norm/getTree/${assessId}/${deptId}/${normType}`,
    {
      assign,
    }
  );
};

export const saveManageDeptAllocationOfIndexApi = (params: any) => {
  return requestByPost("/api/cms/dept/norm/save", params);
};

export const getManageRoleGroupListApi = (assessId: string | number) => {
  return requestByGet(`/api/cms/group/detail/${assessId}`);
};

export const saveManageRoleGroupApi = (params: {
  assessId: number | string;
  userIds: string;
}) => {
  return requestByPost<IManageRoleGroupItem>("/api/cms/group/save", params);
};

export const deleteManageRoleGroupApi = (ids: string | number) => {
  return requestByGet(`/api/cms/group/removes/${ids}`);
};

export const saveManageAssOperationWeightApi = (
  id: number | string,
  weight: number | string
) => {
  return requestByPost(`/api/cms/assessOperation/setWeight/${id}/${weight}`);
};

// 分配指标-检查指标被分配给多个部门
export const checkManageIndexApi = (params: {
  assessId: number | string;
  normIds: string;
}) => {
  return requestByPost<IAssIndexDetail[]>("/api/cms/dept/norm/check", params);
};

// 考核填报-上传附件
export const saveManageFileApi = (params: ISaveManageFileParams) => {
  return requestByPost("/api/cms/fill/file/saveEntity", params);
};

// 指标考核-列表
export const getManageNormListApi = (params: {
  deptId: string | number;
  searchKey?: string;
  uploadStatus?: YES_OR_NO;
}) => {
  return requestByPost<IManageNormItem[]>("/api/cms/fill/norm/getList", params);
};

// 附件管理-列表
export const getManageFileListAPi = (params: any) => {
  return requestByPost("/api/cms/annex/page", params);
};

// 自评得分
export const saveSelfScoreApi = (
  id: number | string,
  score: number | string
) => {
  return requestByGet(`/api/cms/fill/norm/updateScore/${id}/${score}`);
};

// 查看指标&考核单资料列表
export const getFileListApi = (
  assessId: number,
  type: "norm" | "assess",
  moduleId: number
) => {
  return requestByGet<MaterialType[]>(
    `/api/cms/fill/norm/getFile/${moduleId}/${type}/${assessId}`
  );
};

// 删除资料
export const deleteFileApi = (ids: string | number) => {
  return requestByGet(`/api/cms/fill/file/removes/${ids}`);
};

// 考核单提交
export const submitAssessmentApi = (deptId?: string) => {
  return requestByGet(`/api/cms/fill/save/${deptId}`);
};

// 考核单审核
export const examineAssessmentApi = (
  id: number | string,
  status: DEPT_STATUS_ENUM
) => {
  return requestByPost(`/api/cms/fill/audit/${id}/${status}`);
};

// 附加项-评定意见
export const additionalEvaOpinionApi = (params: {
  assessId: number;
  deptId: number;
  opinionJson: string;
  type: "add" | "sub";
}) => {
  return requestByPost("/api/cms/review/addItem/opinion", params);
};

// 考核评定-评定意见
export const assessmentEvaOpinionApi = (params: {
  deptId: number;
  opinion: string;
}) => {
  return requestByPost("/api/cms/review/dept/opinion", params);
};

// 考核评定-设置资料是否合格
export const changeMaterialConditionApi = (params: {
  condition: REVIEW_MATERIAL_TYPE;
  deptId: number;
  materialId: number;
}) => {
  return requestByPost("/api/cms/review/material/condition", params);
};

// 考核评定-资料-评定意见
export const materialEvaOpinionApi = (params: {
  deptId: number;
  materialId: number;
  opinion: string;
}) => {
  return requestByPost("/api/cms/review/material/opinion", params);
};

// 考核评定-指标-评定
export const normEvaOpinionApi = (params: {
  deptId: number;
  deptNormId: number;
  mats: {
    condition: REVIEW_MATERIAL_TYPE;
    materialId: number;
    opinion: string;
  }[];
  opinionScore?: number;
}) => {
  return requestByPost("/api/cms/review/norm/opinion", params);
};

// 考核评定-资料列表
export const getReviewNormListApi = (params: {
  deptId: string | number;
  searchKey?: string;
  uploadStatus?: YES_OR_NO;
}) => {
  return requestByPost<IManageNormItem[]>(
    "/api/cms/review/norm/getList",
    params
  );
};

// 考核评定-提交
export const saveReviewApi = (assessId: number) => {
  return requestByGet(`/api/cms/review/save/${assessId}`);
};

// 考核评定-退回
export const refundReviewApi = (assessId: number, deptId: number) => {
  return requestByGet(`/api/cms/review/dept/return/${deptId}/${assessId}`);
};

// 附件归档
export const changeArchiveApi = (
  condition: ARCHIVE_TYPE,
  materialId: number
) => {
  return requestByGet(`/api/cms/annex/archive/${materialId}/${condition}`);
};
