package com.blueland.bpm.engine.config.model;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.Length;

import com.blueland.bpm.common.base.BaseEntity;
import com.blueland.bpm.common.util.DateConvertUtils;
import com.blueland.bpm.engine.core.model.ProcessDefinitionModel;

/**
 * @author lw
 * @version 1.0
 * @since  
 */


public class ProcessInfoConfig extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	

	//date formats
	
	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
    /**
     * 流程定义ID       db_column: PROCESS_DEF_ID 
     */	
	@Length(max=100)
	private String processDefId;
    /**
     * 流程定义名称       db_column: PROCESS_DEF_NAME 
     */	
	@Length(max=100)
	private String processDefName;
    /**
     * 流程类型       db_column: PROCESS_TYPE_ID 
     */	
	@Length(max=50)
	private String processTypeId;
	private String processTypeName;
    /**
     * 流程表单URL       db_column: PROCESS_PAGE_URL 
     */	
	@Length(max=1000)
	private String processPageUrl;
    /**
     * 流程表单数据       db_column: PROCESS_PAGE_INFO 
     */	
	@Length(max=4000)
	private String processPageInfo;
    /**
     * 流程表单起草权限       db_column: PROCESS_START_AUTH 
     */	
	@Length(max=500)
	private String processStartAuth;
    /**
     * 新建流程是否可见       db_column: PROCESS_START_ISSHOW 
     */	
	@Length(max=10)
	private String processStartIsshow;
	
	private int processVersion;
	private String processDefKey;
    /**
     * 备注       db_column: REMARK 
     */	
	@Length(max=500)
	private String remark;
	
	private String pageIshowSelectUserTree;
	
	private String processHandlerClassPath;
	/**
	 * 排序号
	 */
	private Integer processStartOrder;
	
	private String deploymentId;
	/**
	 * 创建时间
	 */
	private Date createTime;
	/**
	 * 最好更新时间
	 */
	
	private Date lastUpdateTime;
	/**
	 * 扩展属性
	 */
	private List<DataObject> dataObjects;
	//columns END
	private static Map processStartIsshowMap=new LinkedHashMap();
	/**
	 * 租户ID
	 */
	private String tenantId;
	/**
	 * 手机端处理状态
	 */
	private String otherSysDealStatus;
	/**
	 * arisr流程编码
	 */
	private String arisCode;
	
	private String cprotocol;
	private String murl;
	private String mprotocol;
	/**
	 * 流程定义管理状态
	 */
	private String processMgrState;
	private static Map processMgrStateMap=new LinkedHashMap();
	public static String PROCESS_START_ISSHOW_YES="Y";
	public static String PROCESS_START_ISSHOW_NO="Y";
	public static String PROCESS_MGR_STATE_UNRELEASE="UNRELEASE";
	public static String PROCESS_MGR_STATE_UPDATE="UPDATE";
	public static String PROCESS_MGR_STATE_RELEASE="RELEASE";
	
	static{
		processStartIsshowMap.put("Y","可见");
		processStartIsshowMap.put("N","不可见");
		processMgrStateMap.put("UNRELEASE","未发布");
		processMgrStateMap.put("UPDATE","修订中");
		processMgrStateMap.put("RELEASE","已发布");
	}
	private List<ActivityInfoConfig> activityInfoConfigs;
	private List<ActivityRule> activityRules;
	/**
	 * 扩展属性
	 */
	private List<DataObjectRelation> dataObjectRelations;
	/**
	 * 流程定义与模型同步状态，Y:已同步,N:未同步
	 */
	private String processModelSyncState;
	public static String PROCESS_MODEL_SYNC_STATE_Y="Y";
	public static String PROCESS_MODEL_SYNC_STATE_N="N";
	/**
	 * 流程定义管理状态：Y:可见，N:不可见'
	 */
	private String processMgrIsshow;
	
	public static String PROCESS_MGR_ISSHOW_Y="Y";
	public static String PROCESS_MGR_ISSHOW_N="N";
	public static ProcessInfoConfig build(ProcessDefinitionModel processDefinition){
		ProcessInfoConfig processInfoConfig=new ProcessInfoConfig();
		processInfoConfig.processDefId=processDefinition.getProcDefId();
		processInfoConfig.processDefKey=processDefinition.getProcDefKey();
		processInfoConfig.processDefName=processDefinition.getProcDefName();
		processInfoConfig.deploymentId=processDefinition.getDeploymentId();
		processInfoConfig.processVersion=processDefinition.getVersion();
		processInfoConfig.tenantId=processDefinition.getTenantId();
		Date nowDate=new Date();
		processInfoConfig.createTime=nowDate;
		processInfoConfig.lastUpdateTime=nowDate;
		processInfoConfig.processStartIsshow="Y";
		processInfoConfig.processMgrState="UNRELEASE";
		processInfoConfig.setOtherSysDealStatus("yes");
		processInfoConfig.setCprotocol("hnzy:workitem");
		processInfoConfig.setMprotocol("none");
		return processInfoConfig;
	}
	
	
	public ProcessInfoConfig(){
	}

	public ProcessInfoConfig(
		String processDefId
	){
		this.processDefId = processDefId;
	}

	public void setProcessDefId(String value) {
		this.processDefId = value;
	}
	
	public String getProcessDefId() {
		return this.processDefId;
	}
	public void setProcessDefName(String value) {
		this.processDefName = value;
	}
	
	public String getProcessDefName() {
		return this.processDefName;
	}
	public void setProcessTypeId(String value) {
		this.processTypeId = value;
	}
	
	public String getProcessTypeId() {
		return this.processTypeId;
	}
	public void setProcessPageUrl(String value) {
		this.processPageUrl = value;
	}
	
	public String getProcessPageUrl() {
		return this.processPageUrl;
	}
	public void setProcessPageInfo(String value) {
		this.processPageInfo = value;
	}
	
	public String getProcessPageInfo() {
		return this.processPageInfo;
	}
	public void setProcessStartAuth(String value) {
		this.processStartAuth = value;
	}
	
	public String getProcessStartAuth() {
		return this.processStartAuth;
	}
	public void setProcessStartIsshow(String value) {
		this.processStartIsshow = value;
	}
	
	public String getProcessStartIsshow() {
		return this.processStartIsshow;
	}
	public void setRemark(String value) {
		this.remark = value;
	}
	
	public String getRemark() {
		return this.remark;
	}

	public int getProcessVersion() {
		return processVersion;
	}

	public void setProcessVersion(int processVersion) {
		this.processVersion = processVersion;
	}

	public String getProcessDefKey() {
		return processDefKey;
	}

	public void setProcessDefKey(String processDefKey) {
		this.processDefKey = processDefKey;
	}

	public String getPageIshowSelectUserTree() {
		return pageIshowSelectUserTree;
	}

	public void setPageIshowSelectUserTree(String pageIshowSelectUserTree) {
		this.pageIshowSelectUserTree = pageIshowSelectUserTree;
	}

	public String getProcessHandlerClassPath() {
		return processHandlerClassPath;
	}

	public void setProcessHandlerClassPath(String processHandlerClassPath) {
		this.processHandlerClassPath = processHandlerClassPath;
	}

	public Integer getProcessStartOrder() {
		return processStartOrder;
	}

	public void setProcessStartOrder(Integer processStartOrder) {
		this.processStartOrder = processStartOrder;
	}
	
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getLastUpdateTime() {
		return lastUpdateTime;
	}

	public void setLastUpdateTime(Date lastUpdateTime) {
		this.lastUpdateTime = lastUpdateTime;
	}

	public String getProcessTypeName() {
		return processTypeName;
	}

	public void setProcessTypeName(String processTypeName) {
		this.processTypeName = processTypeName;
	}

	public boolean isProcessRelease(){
		return "1".equals(this.processStartIsshow);
	}

	public String getDeploymentId() {
		return deploymentId;
	}

	public void setDeploymentId(String deploymentId) {
		this.deploymentId = deploymentId;
	}
	
	public String getProcessStartIsshowVal(){
		return (String) (processStartIsshowMap.get(processStartIsshow)!=null?processStartIsshowMap.get(processStartIsshow):"");
	}

	public String getProcessMgrStateVal(){
		return (String) (processMgrStateMap.get(processMgrState)!=null?processMgrStateMap.get(processMgrState):"");
	}
	
	public List<ActivityRule> getActivityRules() {
		return activityRules;
	}

	public void setActivityRules(List<ActivityRule> activityRules) {
		this.activityRules = activityRules;
	}

	public  Map getProcessStartIsshowMap() {
		return processStartIsshowMap;
	}
	public String getCreateTimeString() {
		return DateConvertUtils.format(getCreateTime(), DATE_FORMAT);
	}
	public String getLastUpdateTimeString() {
		return DateConvertUtils.format(getLastUpdateTime(), DATE_TIME_FORMAT);
	}
	public boolean isRelease(){
		return "RELEASE".equals(this.processMgrState);
	}
	
	public boolean isUpdate(){
		return "UPDATE".equals(this.processMgrState);
	}

	public String getTenantId() {
		return tenantId;
	}

	public void setTenantId(String tenantId) {
		this.tenantId = tenantId;
	}

	public List<ActivityInfoConfig> getActivityInfoConfigs() {
		return activityInfoConfigs;
	}

	public void setActivityInfoConfigs(List<ActivityInfoConfig> activityInfoConfigs) {
		this.activityInfoConfigs = activityInfoConfigs;
	}

	public List<DataObject> getDataObjects() {
		return dataObjects;
	}

	public void setDataObjects(List<DataObject> dataObjects) {
		this.dataObjects = dataObjects;
	}

	

	
	public String getProcessMgrIsshow() {
		return processMgrIsshow;
	}


	public void setProcessMgrIsshow(String processMgrIsshow) {
		this.processMgrIsshow = processMgrIsshow;
	}


	public String getProcessMgrState() {
		return processMgrState;
	}


	public void setProcessMgrState(String processMgrState) {
		this.processMgrState = processMgrState;
	}


	public static Map getProcessMgrStateMap() {
		return processMgrStateMap;
	}


	public String getProcessModelSyncState() {
		return processModelSyncState;
	}


	public void setProcessModelSyncState(String processModelSyncState) {
		this.processModelSyncState = processModelSyncState;
	}



	public String getCprotocol() {
		return cprotocol;
	}


	public void setCprotocol(String cprotocol) {
		this.cprotocol = cprotocol;
	}


	public String getMurl() {
		return murl;
	}


	public void setMurl(String murl) {
		this.murl = murl;
	}


	public String getMprotocol() {
		return mprotocol;
	}


	public void setMprotocol(String mprotocol) {
		this.mprotocol = mprotocol;
	}


	public String toString() {
		return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE);
	}

	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getProcessDefId())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof ProcessInfoConfig == false) return false;
		if(this == obj) return true;
		ProcessInfoConfig other = (ProcessInfoConfig)obj;
		return new EqualsBuilder()
			.append(getProcessDefId(),other.getProcessDefId())
			.isEquals();
	}


	public String getOtherSysDealStatus() {
		return otherSysDealStatus;
	}


	public void setOtherSysDealStatus(String otherSysDealStatus) {
		this.otherSysDealStatus = otherSysDealStatus;
	}


	public String getArisCode() {
		return arisCode;
	}


	public void setArisCode(String arisCode) {
		this.arisCode = arisCode;
	}


	public List<DataObjectRelation> getDataObjectRelations() {
		return dataObjectRelations;
	}


	public void setDataObjectRelations(List<DataObjectRelation> dataObjectRelations) {
		this.dataObjectRelations = dataObjectRelations;
	}

}

