package com.epam.ta.reportportal.entity;

import com.epam.ta.reportportal.entity.enums.PostgreSQLEnumType;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.time.LocalDateTime;

/**
 * Activity table entity
 *
 * @author Andrei Varabyeu
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "activity", schema = "public")
@TypeDef(name = "jsonb", typeClass = JsonMap.class)
@TypeDef(name = "pqsql_enum", typeClass = PostgreSQLEnumType.class)
public class Activity {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", unique = true, nullable = false, precision = 64)
	private Long id;

	@Column(name = "user_id", nullable = false, precision = 32)
	private Long userId;

	@Column(name = "project_id", nullable = false)
	private Long projectId;

	@Enumerated(EnumType.STRING)
	@Column(name = "entity", unique = true, nullable = false)
	@Type(type = "pqsql_enum")
	private Entity entity;

	@Column(name = "action", nullable = false)
	private String action;

	@Column(name = "details")
	@Type(type = "jsonb")
	private JsonbObject details;

	@Column(name = "creation_date")
	private LocalDateTime createdAt;

	@Column(name = "object_id")
	private Long objectId;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public Long getProjectId() {
		return projectId;
	}

	public void setProjectId(Long projectId) {
		this.projectId = projectId;
	}

	public Entity getEntity() {
		return entity;
	}

	public void setEntity(Entity entity) {
		this.entity = entity;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public JsonbObject getDetails() {
		return details;
	}

	public void setDetails(JsonbObject details) {
		this.details = details;
	}

	public LocalDateTime getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(LocalDateTime createdAt) {
		this.createdAt = createdAt;
	}

	public Long getObjectId() {
		return objectId;
	}

	public void setObjectId(Long objectId) {
		this.objectId = objectId;
	}

	public enum Entity {
		LAUNCH,
		ITEM,
		DASHBOARD,
		DEFECT_TYPE,
		EMAIL_CONFIG,
		FILTER,
		IMPORT,
		INTEGRATION,
		ITEM_ISSUE,
		PROJECT,
		SHARING,
		TICKET,
		USER,
		WIDGET
	}
}

@@ -1,8 +1,615 @@
+/*%0A *  Copyright (C) 2018 EPAM Systems%0A *%0A *  Licensed under the Apache License, Version 2.0 (the %22License%22);%0A *  you may not use this file except in compliance with the License.%0A *  You may obtain a copy of the License at%0A *%0A *  http://www.apache.org/licenses/LICENSE-2.0%0A *%0A *  Unless required by applicable law or agreed to in writing, software%0A *  distributed under the License is distributed on an %22AS IS%22 BASIS,%0A *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A *  See the License for the specific language governing permissions and%0A *  limitations under the License.%0A */%0A%0A
 package 
@@ -1665,29 +1665,53 @@
 private 
-Entity e
+ActivityEntityType activityE
 ntity
+Type
 ;%0A%0A%09@Col
@@ -2325,24 +2325,48 @@
 lic 
-Entity get
+ActivityEntityType getActivity
 Entity
+Type
 () %7B
@@ -2375,22 +2375,34 @@
 %09return 
-e
+activityE
 ntity
+Type
 ;%0A%09%7D%0A%0A%09p
@@ -2419,28 +2419,64 @@
  set
-Entity(Entity e
+ActivityEntityType(ActivityEntityType activityE
 ntity
+Type
 ) %7B%0A
@@ -2486,23 +2486,47 @@
 his.
-entity = e
+activityEntityType = activityE
 ntity
+Type
 ;%0A%09%7D
@@ -3068,22 +3068,34 @@
 ic enum 
+Activity
 Entity
+Type
  %7B%0A%09%09LAU

Add header. Rename enum(Entity -> ActivityEntityType)