import {
  ASS_INDEX_TYPE,
  AssIndexTreeItemType,
  IAssIndexDetail,
  IFileTemplateFormParams,
  IFileTemplateFormResponse,
  IAssTemplateDetail,
  IAssInspectionItem,
} from "@/types";
import { requestByGet, requestByPost } from "@dage/service";

/**
 * ====================
 * 考核指标 API
 * ====================
 */

/**
 * 获取指标设置列表树
 * @param {ASS_INDEX_TYPE} type (ASS_INDEX_TYPE.FIXED)
 */
export const getAssIndexTreeApi = (type = ASS_INDEX_TYPE.FIXED) => {
  return requestByGet<AssIndexTreeItemType[]>(`/api/cms/norm/getTree/${type}`);
};

export const getAssIndexDetailApi = (id: number) => {
  return requestByGet<IAssIndexDetail>(`/api/cms/norm/detail/${id}`);
};

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

export const saveEntityApi = (
  params: IFileTemplateFormParams,
  type: "norm" | "assess"
) => {
  return requestByPost<IFileTemplateFormResponse>(
    `/api/cms/${type}/file/saveEntity`,
    params
  );
};

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

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

export const saveAssInspectionApi = (params: IAssInspectionItem[]) => {
  return requestByPost<number[]>("/api/cms/norm/gist/saveEntity", params);
};

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

// 检查打分点是否存在次级
export const checkAssIsPointApi = (id: string | number) => {
  return requestByGet(`/api/cms/norm/checkPoint/${id}`);
};

/**
 * ====================
 * 考核模板 API
 * ====================
 */

/** 获取考核模板列表 */
export const getAssTemplateListApi = (
  type: ASS_INDEX_TYPE,
  searchKey?: string
) => {
  return requestByGet<IAssTemplateDetail[]>(
    `/api/cms/template/getList/${type}`,
    {
      searchKey,
    }
  );
};

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

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

export const getAssTemplateDetailApi = (id: string | number) => {
  return requestByGet<IAssTemplateDetail>(`/api/cms/template/detail/${id}`);
};
