import { request } from "umi";

export type commonParams = {
  currentPage: number;
  pageSize: number;
  orderByProperty?: string;
  Ascending?: boolean;
  totalPage?: number;
  totalCount?: number;
  filters?: any[];
};

/**
 * 查询多语言
 * @param data {maxCount: number, searchKey: string, searchLan: "zh-CN" | "en"}
 * @returns
 */
export const ListLangBySearchKey = (data: {
  maxCount: number;
  searchKey: string;
  searchLan: "zh-CN" | "en";
}) => {
  return request("/api/system/ListLangBySearchKey", {
    method: "POST",
    data,
  });
};

/**
 * 场景查询
 * @param data 
 * @returns 
 * {
    "currentPage": 1,
    "pageSize": 10,
    "orderByProperty": "Id",
    "Ascending": false,
    "totalPage": 1,
    "totalCount": 1,
    "filters": [
        {
            "name": "EnterpriseId"
        }
    ]
}
 */
export const GetAllWfScene = (data: commonParams) => {
  return request("/api/wfScene/GetAllWfScene", {
    method: "POST",
    data,
  });
};

/**
 * 流程查询
 * @param data 
 * @returns 
 * {
    "currentPage": 1,
    "pageSize": 10,
    "orderByProperty": "Id",
    "Ascending": false,
    "totalPage": 1,
    "totalCount": 1,
    "filters": [
        {
            "name": "EnterpriseId"
        }
    ]
}
 */
export const GetAllWorkflows = (data: commonParams) => {
  return request("/api/workflow/GetAllWorkflows", {
    method: "POST",
    data,
  });
};

/**
 * 获取全部页面
 * @param data
 * @returns
 */
export const GetAllPage = () => {
  return request<{
    codeItemCount: number;
    description: string;
    directory: string;
    fileName: string;
    id: string;
    isFavourite: boolean;
    is_page_load_from_localhost: boolean;
    langDescription: string;
    langName: string;
    menuLinkUrl: string;
    name: string;
    processStatus: string;
    randerType: number;
    reportType: number;
    type: number;
  }>("/api/bpm/GetAllPage", {
    method: "POST",
  });
};

/**
 * 获取全部视图和表
 * @param data
 * @returns
 */
export const GetAllTablesAndViews = () => {
  return request<{
    appBusinessTables: {
      aliasName: string;
      description: string;
      id: string;
      isLatest: boolean;
      latest: boolean;
      name: string;
      schemaName: string;
      type: number;
    }[];
    bpmViewTables: {
      description: string;
      directory: string;
      id: string;
      name: string;
      schemaName: string;
      type: number;
    }[];
  }>("/api/table/GetAllTablesAndViews", {
    method: "POST",
  });
};

/**
 * 上传文件
 * @param file 
 * @returns
 */
export const UploadFile = (data: FormData) => {
  return request<{
    code: number;
    result: {
      id: string
    }[]
  }>("/fileApi/File/UploadFiles", {
    method: "POST",
    headers: {
      "Content-Type": "multipart/form-data",
    },
    data,
  });
};

/**
 * 获取文件
 * @param fileId 文件id 
 * @returns
 */
export const GetFile = (data: {fileId: string}) => {
  return request("/File/GetImage", {
    method: "GET",
    params: data,
    responseType: "blob",
  });
};
