package com.blueland.bpm.engine.core.service;

import java.io.InputStream;
import java.util.List;

import org.activiti.bpmn.model.BpmnModel;
import org.activiti.engine.repository.Model;
import org.activiti.validation.ValidationError;

import com.blueland.bpm.engine.core.model.ProcessDefinitionModel;
import com.blueland.bpm.engine.util.WorkFlowException;
/**
 * 流程模型Service
 * @version:  1.0
 * @author lw 
 */
public interface ProcessModelService  extends ActivitiService{
	/**
	 * 将流程Json模型转换成字节码
	 * @param modelData
	 * @return byte[]
	 */
	public byte[] convertJsonModelToByte(String modelId) throws WorkFlowException;
	
	/**
	 * 将流程对象模型转换成字节码
	 * @param modelData
	 * @return byte[]
	 */
	public byte[] convertBpmnModelToByte(BpmnModel bpmnModel) throws WorkFlowException;
	/**
	 * 将流程对象模型转换成字节码
	 * @param bpmnModel
	 * @param processDefId
	 * @return
	 * @throws WorkFlowException
	 */
	public byte[] convertBpmnModelToByte(BpmnModel bpmnModel,String processDefId) throws WorkFlowException;
	
	/**
	 * 将流程文件转换成流程对象模型
	 * @param modelData
	 * @return byte[]
	 */
	public BpmnModel convertFileToBpmnModel(InputStream in)throws WorkFlowException;
	
	BpmnModel convertJsonModelToBpmnModel(Model modelData);
	/**
	 * 获取流程对象模型
	 * @param modelId
	 * @return
	 */
	public BpmnModel getBpmnModelByModelId(String modelId);
	/**
	 * 获取流程对象模型
	 * @param procDefId
	 * @return
	 */
	public BpmnModel getBpmnModelByProcDefId(String procDefId);
	/**
	 * 同步流程对象模型至数据库表
	 * @param processDefinition
	 * @return
	 */
	public boolean syncBpmnModelToDb(ProcessDefinitionModel processDefinition);
	/**
	 * 同步流程对象模型至数据库表
	 * @param processDefinition
	 * @param modelId
	 * @return
	 */
	public boolean syncBpmnModelToDb(ProcessDefinitionModel processDefinition,String modelId);
	/**
	 * 同步流程对象模型至流程Json模型并入库
	 * @param procDefId
	 * @return
	 */
	public boolean syncProcessModelToJsonModel(String procDefId);
	
	
	public void syncProcessModelToJsonModelByUpdate(String modelKey);
	/**
	 * 验证BPMN文件
	 * @param in
	 * @return
	 */
	public List<ValidationError> validateBpmnXml(InputStream in) ;
	/**
	 * 验证BPMN模型
	 * @param in
	 * @return
	 */
	public List<ValidationError> validateBpmnModel(BpmnModel bpmnModel) ;

	public boolean isPprocessDeployment (String modelId,String tenantId);
	
	public boolean isProcessUpdate(String modelId);
	
	public String getFlowElementUptMsg(String modelId) ;
	/**
	 * 根据Model部署流程
	 */
	public String deploy(String modelId,String tenantId);
	

	/**
	 * 直接覆盖已有流程定义版本，并更新流程定义的缓存
	 */
	public String deployCascodeUpdate(String modelId);
	
	/**
	 * 导入流程文件
	 * @param fileBytes
	 * @param tenantId
	 * @return
	 */
	public BpmnModel importBpmnFile(byte[] fileBytes,String tenantId)throws WorkFlowException;
	
	/**
	 * 更新模型部署状态
	 */
	public void updateModelState(String key, String tenantId,String modelState);

	/**
	 * 创建模型
	 */
	public String create(String name, String key, String description,String tenantId);
	/**
	 * 复制模型
	 */
	public void copy(String modelId, String name, String key,String description) ;
}
