import { request } from "umi";

export * from "./dataModel";

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

/**
 * 根据key查询多语言
 * @param data {key: string}
 * @returns
 */
export const ListLangByKey = (data: {
  key: string;
}) => {
  return request("/api/system/ListLangByKey", {
    method: "POST",
    data,
  });
};

/**
 * 获取表格字段列表
 * @param data 
 * @returns 
 */
export const GetAllBusinessTableColumns = (data: commonParams) => {
  return request("/api/table/GetAllBusinessTableColumns", {
    method: "POST",
    data
  });
}

/**
 * 获取全部表格设计
 * @param data 
 * @returns 
 */
export const GetAllDesignTables = () => {
  return request("/api/table/GetAllTablesAndViews", {
    method: "POST",
  });
};

/**
 * 获取表格详情
 * @param data 
 * @returns 
 */
export const GetBusinessTablesByTableId = (data: any) => {
  return request("/api/table/GetBusinessTablesByTableId", {
    method: "POST",
    data
  });
};


/**
 * 上传文件
 * @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",
  });
};

/**
 * 获取变量
 * @returns
 */
export const GetSystemVariable = () => {
  return request("/api/workflow/GetAllWorkflowVariable", {
    method: "POST",
  });
};