import { request } from "umi";
import { commonParams } from ".";
import { NodeType, EventType } from "@/enum";

type NodeItemType = {
  name: string;
  type: NodeType;
  id: string;
  x: number;
  y: number;
  width: number;
  height: number;
  imageSrc: string;
  shapeType: number;
  wfdWorkflowId: string;
  text?: string;
  langText?: string;
  langNameList?: Record<string, string>[];
};

export type ActionItemType = {
  isEnable: boolean;
  displayOrder: number;
  actionLinkId: string;
  langNameList: Record<string, string>[];
  workflowNodes: Record<string, string>[];
  type: EventType;
  langName: string;
  returnToNodes: string;
  returnToExceptNodes: string;
  variableValue: string;
  id?: string;
};

/**
 * 获取流程图详情
 * @param data {id: string}
 * @returns
 */
export const GetWorkFlow = (data: { id: string }) => {
  return request("/api/workflow/GetWorkflow", {
    method: "POST",
    data,
  });
};

/**
 * 新增/编辑节点
 * @param data
 * @returns
 */
export const SaveNode = (data: NodeItemType) => {
  return request("/api/workflow/SaveNode", {
    method: "POST",
    data,
  });
};

/**
 * 删除节点
 * @param data {id: string}
 * @returns
 */
export const DeleteNode = (data: NodeItemType) => {
  return request("/api/workflow/DeleteNode", {
    method: "POST",
    data,
  });
};

/**
 * 获取节点详情
 * @param data
 * @returns
 */
export const GetNode = (data: { id: string }) => {
  return request("/api/workflow/GetNode", {
    method: "POST",
    data,
  });
};

/**
 * 保存节点数据
 * @param data
 * @returns
 */
export const SaveNodeData = (data: any) => {
  return request("/api/workflow/SaveNodeData", {
    method: "POST",
    data,
  });
};

/**
 * 编辑禁止撤回
 * @param data
 * @returns
 */
export const EditNodeDisableRecall = (data: any) => {
  return request("/api/workflow/EditNodeDisableRecall", {
    method: "POST",
    data,
  });
};

/**
 * 获取节点关联页面
 * @param data
 * @returns
 */
export const GetPageByNodeId = (data: { id: string }) => {
  return request("/api/workflow/GetPageByNodeId", {
    method: "POST",
    data,
  });
};

/**
 * 获取节点可关联页面
 * @param data
 * @returns
 */
export const GetPagesForWorkflowNode = (data: commonParams) => {
  return request("/api/form/GetPagesForWorkflowNode", {
    method: "POST",
    data,
  });
};

/**
 * 获取动作
 * @param data
 * @returns
 */
export const GetNodeActions = (data: { id: string }) => {
  return request("/api/workflow/GetNodeActions", {
    method: "POST",
    data,
  });
};

/**
 * 编辑动作
 * @param data
 * @returns
 */
export const EditNodeAction = (data: ActionItemType) => {
  return request("/api/workflow/EditNodeAction", {
    method: "POST",
    data,
  });
};

/**
 * 批量编辑动作
 * @param data
 * @returns
 */
export const EditNodeActions = (data: ActionItemType[]) => {
  return request("/api/workflow/EditNodeActions", {
    method: "POST",
    data,
  });
};

/**
 * 修改动作启用
 * @param data
 * @returns
 */
export const EditActionEnable = (data: ActionItemType) => {
  return request("/api/workflow/EditActionEnable", {
    method: "POST",
    data,
  });
};

/**
 * 删除动作
 * @param data
 * @returns
 */
export const DeleteActionReturnToNodes = (data: ActionItemType) => {
  return request("/api/workflow/DeleteActionReturnToNodes", {
    method: "POST",
    data,
  });
};

/**
 * 获取除自身节点之外的其它流程节点列表
 * @param data
 * @returns
 */
export const GetOtherStepNodes = (data: { id: string; selectedId: string }) => {
  return request("/api/workflow/GetOtherStepNodes", {
    method: "POST",
    data,
  });
};

/**
 * 启用/禁用考核
 * @param data
 * @returns
 */
export const EditExamineEnable = (data: {
  id: string;
  isExamineEnable: boolean;
}) => {
  return request("/api/workflow/EditExamineEnable", {
    method: "POST",
    data,
  });
};

/**
 * 编辑考核时间
 * @param data
 * @returns
 */
export const EditExamineStandardTime = (data: {
  id: string;
  examineStandardTime: string;
}) => {
  return request("/api/workflow/EditExamineStandardTime", {
    method: "POST",
    data,
  });
};

/**
 * 获取对象详情
 * @param data
 * @returns
 */
export const GetObject = (data: { id: string }) => {
  return request("/api/workflow/GetObject", {
    method: "POST",
    data,
  });
};

/**
 * 新增/编辑对象
 * @param data
 * @returns
 */
export const EditObject = (data: NodeItemType) => {
  return request("/api/workflow/EditObject", {
    method: "POST",
    data,
  });
};

/**
 * 删除对象
 * @param data
 * @returns
 */
export const DeleteObject = (data: NodeItemType) => {
  return request("/api/workflow/DeleteObject", {
    method: "POST",
    data,
  });
};

/**
 * 启用准入条件
 * @param data
 * @returns
 */
export const EditEntryEnable = (data: {
  id: string;
  isEntryEnable: boolean;
  entryCondition: string;
}) => {
  return request("/api/workflow/EditEntryEnable", {
    method: "POST",
    data,
  });
};

/**
 * 编辑准入条件
 * @param data
 * @returns
 */
export const EditEntryCondition = (data: {
  id: string;
  isEntryEnable: boolean;
  entryCondition: string;
}) => {
  return request("/api/workflow/EditEntryCondition", {
    method: "POST",
    data,
  });
};

/**
 * 获取准入条件查看结果
 * @param data
 * @returns
 */
export const GetFormattedResult = (data: { data: string }) => {
  return request("/api/workflow/GetFormattedResult", {
    method: "POST",
    data,
  });
};

/**
 * 编辑处理方式
 * @param data
 * @returns
 */
export const EditProcessType = (data: {
  id: string;
  processType: 0 | 1 | 2;
}) => {
  return request("/api/workflow/EditProcessType", {
    method: "POST",
    data,
  });
};

/**
 * 编辑跳过方式
 * @param data
 * @returns
 */
export const EditJumpTypeBinary = (data: any) => {
  return request("/api/workflow/EditJumpTypeBinary", {
    method: "POST",
    data,
  });
};

/**
 * 编辑跳过方式
 * @param data
 * @returns
 */
export const EditJumpNodeId = (data: any) => {
  return request("/api/workflow/EditJumpNodeId", {
    method: "POST",
    data,
  });
};

/**
 * 获取全部配置
 * @param data
 * @returns
 */
export const GetAllColumnConfigs = (data: { id: string }) => {
  return request("/api/workflow/GetAllColumnConfigs", {
    method: "POST",
    data,
  });
};

/**
 * 获取字段
 * @param data
 * @returns
 */
export const GetInformColums = (data: {
  nodeId: string;
  informLevel: number;
}) => {
  return request("/api/table/GetInformColums", {
    method: "POST",
    data,
  });
};

/**
 * 编辑字段配置
 * @param {
  "columnLinkId": "acf593ab-ee20-4722-8fcd-2da8d7d10c31",
  "columnId": "0ebb9f58-9893-4d31-87c9-509cf281c373",
  "name": "CreationTime",
  "columnLevel": 3,
  "type": 1,
  "columnKey": "InstTask.creationtime"
}
 * @returns
 */
export const EditColumnConfig = (data: any) => {
  return request("/api/workflow/EditColumnConfig", {
    method: "POST",
    data,
  });
};

/**
 * 删除配置
 * @param data
 * @returns
 */
export const DeleteColumnConfig = (data: { id: string }) => {
  return request("/api/workflow/DeleteColumnConfig", {
    method: "POST",
    data,
  });
};

/**
 * 编辑自动处理
 * @param data
 * @returns
 */
export const EditAutoHandle = (data: {
  id: string;
  autoCallType: 1 | 2 | 3;
  autoCallValue: string;
}) => {
  return request("/api/workflow/EditAutoHandle", {
    method: "POST",
    data,
  });
};

/**
 * 获取全部变量
 * @param data
 * @returns
 */
export const GetAllWorkflowVariable = (data: { id: string }) => {
  return request("/api/workflow/GetAllWorkflowVariable", {
    method: "POST",
    data,
  });
};

/**************************** 运维端 **************************** */

/**
 * 获取处理人
 * @param data
 * @returns
 */
export const GetProcessor = (data: { id: string }) => {
  return request("/api/workflow/GetProcessor", {
    method: "POST",
    data,
  });
};

/**
 * 编辑处理人
 * @param data
 * @returns
 */
export const EditWorkflowProcessor = (data: {
  type: number;
  dataType: number;
  dataValue: string;
  baseType: number;
  baseValue: string;
  isActiveConditionEnable: boolean;
  baseDataType: number;
  activeCondition: string;
  processorLinkId: string;
  dataValueName: string;
  baseValueName: string;
}) => {
  return request("/api/workflow/EditWorkflowProcessor", {
    method: "POST",
    data,
  });
};

/**
 * 删除处理人
 * @param data
 * @returns
 */
export const DeleteWorkflowProcessor = (data: {
  activeCondition: string;
  activeConditionEnable: boolean;
  baseType: number;
  dataType: number;
  dataValueName: string;
  displayOrder: number;
  id: string;
  isActiveConditionEnable: boolean;
  processorLinkId: string;
  type: number;
}) => {
  return request("/api/workflow/DeleteWorkflowProcessor", {
    method: "POST",
    data,
  });
};

/**
 * 获取抄送对象
 * @param data
 * @returns
 */
export const GetAllNodeCopyConfigsByCopyLinkId = (id: string) => {
  return request("/api/workflow/GetAllNodeCopyConfigsByCopyLinkId", {
    method: "POST",
    data: id,
  });
};

/**
 * 删除抄送对象
 * @param data
 * @returns
 */
export const DeleteCopyConfig = (data: {
  actionId?: string;
  copyLinkId?: string;
  creationTime?: string;
  creatorUserId?: string;
  id: string;
  processorLinkId?: string;
  $$hashKey?: string;
}) => {
  return request("/api/workflow/DeleteCopyConfig", {
    method: "POST",
    data,
  });
};

/**
 * 获取通知对象
 * @param data
 * @returns
 */
export const GetAllByInformConfigLinkId = (data: {
  informLevel: 3;
  informLinkId: string;
}) => {
  return request("/api/workflow/GetAllByInformConfigLinkId", {
    method: "POST",
    data,
  });
};

/**
 * 编辑通知对象
 * @param data
 * @returns
 */
export const EditNodeInformConfig = (data: {
  actionId: string;
  eventType: string;
  id: string;
  informLevel: number;
  informLinkId: string;
  isDisabled: boolean;
  processorLinkId: string;
  sendWay: number;
  type: number;
  $sendWay: string;
  $$hashKey: "object:1129";
}) => {
  return request("/api/workflow/EditNodeInformConfig", {
    method: "POST",
    data,
  });
};

/**
 * 删除通知对象
 * @param data
 * @returns
 */
export const DeleteNodeInformConfig = (data: {
  actionId: string;
  eventType: string;
  id: string;
  informLevel: number;
  informLinkId: string;
  isDisabled: boolean;
  processorLinkId: string;
  sendWay: number;
  type: number;
  $sendWay: string;
  $$hashKey: string;
}) => {
  return request("/api/workflow/DeleteNodeInformConfig", {
    method: "POST",
    data,
  });
};

/**
 * 过时通知启禁用
 * @param data
 * @returns
 */
export const EditIsOvertimeInformEnable = (data: any) => {
  return request("/api/workflow/EditIsOvertimeInformEnable", {
    method: "POST",
    data,
  });
};

/**
 * 获取过时通知列表
 * @param data
 * @returns
 */
export const GetAllTimeoutRemindConfigByNodeId = (data: { Id: string }) => {
  return request("/api/workflow/GetAllTimeoutRemindConfigByNodeId", {
    method: "POST",
    data,
  });
};

/**
 * 新增过时通知列表
 * @param data
 * @returns
 */
export const AddNodeTimeoutRemindConfig = (data: { Id: string }) => {
  return request("/api/workflow/AddNodeTimeoutRemindConfig", {
    method: "POST",
    data,
  });
};

/**
 * 更新过时通知对象
 * @param data
 * @returns
 */
export const UpdateNodeTimeoutRemindConfig = (data: any) => {
  return request("/api/workflow/UpdateNodeTimeoutRemindConfig", {
    method: "POST",
    data,
  });
};

/**
 * 过时处理启禁用
 * @param data
 * @returns
 */
export const EditIsOvertimeActionEnable = (data: any) => {
  return request("/api/workflow/EditIsOvertimeActionEnable", {
    method: "POST",
    data,
  });
};

/**
 * 获取过时处理列表
 * @param data
 * @returns
 */
export const GetAllTimeoutProcessingConfigByNodeId = (data: { Id: string }) => {
  return request("/api/workflow/GetAllTimeoutProcessingConfigByNodeId", {
    method: "POST",
    data,
  });
};

/**
 * 新增过时处理列表
 * @param data
 * @returns
 */
export const AddNodeTimeoutProcessingConfig = (data: { Id: string }) => {
  return request("/api/workflow/AddNodeTimeoutProcessingConfig", {
    method: "POST",
    data,
  });
};

/**
 * 更新过时通知对象
 * @param data
 * @returns
 */
export const UpdateNodeTimeoutProcessingConfig = (data: any) => {
  return request("/api/workflow/UpdateNodeTimeoutProcessingConfig", {
    method: "POST",
    data,
  });
};

/**
 * 获取预处理人配置
 * @param data
 * @returns
 */
export const GetPreProcessorConfigs = (id: string) => {
  return request("/api/workflow/GetPreProcessorConfigs", {
    method: "POST",
    data: id,
  });
};

/**
 * 新增预处理人配置
 * @param data
 * @returns
 */
export const EditPreProcessorConfig = (data: {
  fixType: 1;
  preProcessorLinkId: string;
}) => {
  return request("/api/workflow/EditPreProcessorConfig", {
    method: "POST",
    data,
  });
};

/**
 * 删除预处理人配置
 * @param data
 * @returns
 */
export const DeletePreProcessorConfig = (data: {
  fixType: 1;
  id: string;
  preProcessorLinkId: string;
  processorLinkId: string;
}) => {
  return request("/api/workflow/DeletePreProcessorConfig", {
    method: "POST",
    data,
  });
};

/**
 * 获取组织树
 * @param data
 * @returns
 */
export const GetGroupTree = () => {
  return request("/api/bpm/GetGroupTree", {
    method: "POST",
    // data,
  });
};

/**
 * 获取角色树
 * @param data
 * @returns
 */
export const GetRoleTree = () => {
  return request("/api/bpm/GetRoleTree", {
    method: "POST",
    // data,
  });
};

/**
 * 获取组织人员列表
 * @param data
 * @returns
 */
export const GetJobs = (data: { GroupId: string }) => {
  return request("/api/bpm/GetJobs", {
    method: "POST",
    data,
  });
};

/**
 * 获取组织人员列表
 * @param data
 * @returns
 */
export const GetAllJobs = (data: { GroupId: string, Filter?: { name: string, value: string } }) => {
  return request("/api/bpm/GetAllJobs", {
    method: "POST",
    data,
  });
};

/**
 * 获取组织人员列表
 * @param data
 * @returns
 */
export const GetJobToUser = (data: { GroupId: string }) => {
  return request("/api/bpm/GetJobToUser", {
    method: "POST",
    data,
  });
};

/**
 * 获取组织人员列表
 * @param data
 * @returns
 */
export const GetAllJobToUser = (data: { GroupId: string }) => {
  return request("/api/bpm/GetAllJobToUser", {
    method: "POST",
    data,
  });
};
