import {
  IManageDeptMaterialItem,
  IManageAssessmentIndex,
  IManageDeptItem,
  IManageFormDetail,
  IManageFormItem,
  IManageFormListParams,
  IManageIndexDetail,
  IManageUserItem,
  PUBLISH_ENUM,
  ASS_INDEX_TYPE,
  IManageDeptAllocationOfIndexItem,
  IManageRoleGroupItem,
  IManageAssOperationResponse,
} 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<IManageAssessmentIndex[]>(
    `/api/cms/assessFixed/save/${id}`,
    indexIds
  );
};

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

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

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);
};
