/*
 * Copyright 2018 Alfresco, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.activiti.api.runtime.event.impl;

import java.util.UUID;

import org.activiti.api.model.shared.event.RuntimeEvent;

public abstract class RuntimeEventImpl<ENTITY_TYPE, EVENT_TYPE extends Enum<?>> implements RuntimeEvent<ENTITY_TYPE, EVENT_TYPE> {

    private String id;
    private Long timestamp;
    private String processInstanceId;
    private String processDefinitionId;
    private String processDefinitionKey;
    private Integer processDefinitionVersion;
    private String businessKey;
    private String parentProcessInstanceId;

    private ENTITY_TYPE entity;

    public RuntimeEventImpl() {
        id = UUID.randomUUID().toString();
        timestamp = System.currentTimeMillis();
    }

    public RuntimeEventImpl(ENTITY_TYPE entity) {
        this();
        this.entity = entity;
    }

    public RuntimeEventImpl(String id,
                            Long timestamp,
                            ENTITY_TYPE entity) {
        this.id = id;
        this.timestamp = timestamp;
        this.entity = entity;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public ENTITY_TYPE getEntity() {
        return entity;
    }

    @Override
    public Long getTimestamp() {
        return timestamp;
    }

    @Override
    public String getProcessInstanceId() {
        return processInstanceId;
    }

    @Override
    public String getProcessDefinitionId() {
        return processDefinitionId;
    }

    @Override
    public String getProcessDefinitionKey() {
        return processDefinitionKey;
    }

    @Override
    public Integer getProcessDefinitionVersion() {
        return processDefinitionVersion;
    }

    @Override
    public String getBusinessKey() {
        return businessKey;
    }

    @Override
    public String getParentProcessInstanceId() {
        return parentProcessInstanceId;
    }

    public void setParentProcessInstanceId(String parentProcessInstanceId) {
        this.parentProcessInstanceId = parentProcessInstanceId;
    }

    public void setProcessDefinitionId(String processDefinitionId) {
        this.processDefinitionId = processDefinitionId;
    }

    public void setProcessDefinitionKey(String processDefinitionKey) {
        this.processDefinitionKey = processDefinitionKey;
    }

    public void setProcessDefinitionVersion(Integer processDefinitionVersion) {
        this.processDefinitionVersion = processDefinitionVersion;
    }

    public void setBusinessKey(String businessKey) {
        this.businessKey = businessKey;
    }

    public void setProcessInstanceId(String processInstanceId) {
        this.processInstanceId = processInstanceId;
    }

    @Override
    public String toString() {
        return "id='" + id + '\'' +
                ", timestamp=" + timestamp +
                ", entity=" + entity;
    }

}

@@ -663,16 +663,42 @@
 .impl;%0A%0A
+import java.util.Objects;%0A
 import j
@@ -3382,117 +3382,2324 @@
     
-return %22id='%22 + id + '%5C'' +%0A                %22, timestamp=%22 + timestamp +%0A                %22, entity=%22 + entity
+StringBuilder builder = new StringBuilder();%0A        builder.append(%22RuntimeEventImpl %5Bid=%22)%0A               .append(id)%0A               .append(%22, timestamp=%22)%0A               .append(timestamp)%0A               .append(%22, processInstanceId=%22)%0A               .append(processInstanceId)%0A               .append(%22, processDefinitionId=%22)%0A               .append(processDefinitionId)%0A               .append(%22, processDefinitionKey=%22)%0A               .append(processDefinitionKey)%0A               .append(%22, processDefinitionVersion=%22)%0A               .append(processDefinitionVersion)%0A               .append(%22, businessKey=%22)%0A               .append(businessKey)%0A               .append(%22, parentProcessInstanceId=%22)%0A               .append(parentProcessInstanceId)%0A               .append(%22, entity=%22)%0A               .append(entity)%0A               .append(%22%5D%22);%0A        return builder.toString();%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        return Objects.hash(businessKey,%0A                            entity,%0A                            id,%0A                            parentProcessInstanceId,%0A                            processDefinitionId,%0A                            processDefinitionKey,%0A                            processDefinitionVersion,%0A                            processInstanceId,%0A                            timestamp);%0A    %7D%0A%0A    @Override%0A    public boolean equals(Object obj) %7B%0A        if (this == obj) %7B%0A            return true;%0A        %7D%0A        if (obj == null) %7B%0A            return false;%0A        %7D%0A        if (getClass() != obj.getClass()) %7B%0A            return false;%0A        %7D%0A        RuntimeEventImpl other = (RuntimeEventImpl) obj;%0A        return Objects.equals(businessKey, other.businessKey) %0A                && Objects.equals(entity, other.entity)%0A                && Objects.equals(id, other.id) %0A                && Objects.equals(parentProcessInstanceId, other.parentProcessInstanceId) %0A                && Objects.equals(processDefinitionId, other.processDefinitionId) %0A                && Objects.equals(processDefinitionKey, other.processDefinitionKey) %0A                && Objects.equals(processDefinitionVersion, other.processDefinitionVersion) %0A                && Objects.equals(processInstanceId, other.processInstanceId) %0A                && Objects.equals(timestamp, other.timestamp)
 ;%0A  

implement equals(), hashCode() and toString() (#146)