/*
 *  Copyright (C) 2018 EPAM Systems
 *
 *  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 com.epam.ta.reportportal.entity.integration;

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

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

/**
 * @author Yauheni_Martynau
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@TypeDef(name = "details", typeClass = IntegrationTypeDetails.class)
@TypeDef(name = "pgsql_enum", typeClass = PostgreSQLEnumType.class)
@Table(name = "integration_type", schema = "public")
public class IntegrationType implements Serializable {

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

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

	@Enumerated(EnumType.STRING)
	@Type(type = "pqsql_enum")
	@Column(name = "auth_flow", nullable = false)
	private IntegrationAuthFlowEnum authFlow;

	@CreatedDate
	@Column(name = "creation_date", nullable = false)
	private LocalDateTime creationDate;

	@Enumerated(EnumType.STRING)
	@Type(type = "pqsql_enum")
	@Column(name = "group_type", nullable = false)
	private IntegrationGroupEnum integrationGroup;

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

	//	@OneToMany(mappedBy = "type", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY, orphanRemoval = true)
	//	@JsonManagedReference(value = "integrationTypes")
	//	private Set<Integration> integrations = Sets.newHashSet();

	public Long getId() {
		return id;
	}

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

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public IntegrationAuthFlowEnum getAuthFlow() {
		return authFlow;
	}

	public void setAuthFlow(IntegrationAuthFlowEnum authFlow) {
		this.authFlow = authFlow;
	}

	public LocalDateTime getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(LocalDateTime creationDate) {
		this.creationDate = creationDate;
	}

	public IntegrationGroupEnum getIntegrationGroup() {
		return integrationGroup;
	}

	public void setIntegrationGroup(IntegrationGroupEnum integrationGroup) {
		this.integrationGroup = integrationGroup;
	}

	public IntegrationTypeDetails getDetails() {
		return details;
	}

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

	//	public Set<Integration> getIntegrations() {
	//		return integrations;
	//	}
	//
	//	public void setIntegrations(Set<Integration> integrations) {
	//		this.integrations = integrations;
	//	}
}

@@ -1,14 +1,13 @@
 /*%0A *
- 
  Copyrig
@@ -36,17 +36,16 @@
 ms%0A *%0A *
- 
  License
@@ -103,17 +103,16 @@
 se%22);%0A *
- 
  you may
@@ -171,17 +171,16 @@
 ense.%0A *
- 
  You may
@@ -217,18 +217,16 @@
 at%0A *%0A *
-  
  http://
@@ -266,17 +266,16 @@
 .0%0A *%0A *
- 
  Unless 
@@ -337,17 +337,16 @@
 tware%0A *
- 
  distrib
@@ -406,17 +406,16 @@
 ASIS,%0A *
- 
  WITHOUT
@@ -482,17 +482,16 @@
 lied.%0A *
- 
  See the
@@ -553,17 +553,16 @@
 s and%0A *
- 
  limitat
@@ -842,24 +842,125 @@
 QLEnumType;%0A
+import com.fasterxml.jackson.annotation.JsonManagedReference;%0Aimport com.google.common.collect.Sets;%0A
 import org.h
@@ -1248,16 +1248,38 @@
 ateTime;
+%0Aimport java.util.Set;
 %0A%0A/**%0A *
@@ -2323,19 +2323,16 @@
 tails;%0A%0A
-%09//
 %09@OneToM
@@ -2430,19 +2430,16 @@
 = true)%0A
-%09//
 %09@JsonMa
@@ -2481,19 +2481,16 @@
 Types%22)%0A
-%09//
 %09private
@@ -3432,19 +3432,16 @@
 ls;%0A%09%7D%0A%0A
-%09//
 %09public 
@@ -3477,19 +3477,16 @@
 ons() %7B%0A
-%09//
 %09%09return
@@ -3505,20 +3505,11 @@
 s;%0A%09
-//%09%7D%0A%09//%0A%09//
+%7D%0A%0A
 %09pub
@@ -3566,19 +3566,16 @@
 ions) %7B%0A
-%09//
 %09%09this.i
@@ -3606,11 +3606,8 @@
 ns;%0A
-%09//
 %09%7D%0A%7D

return back integration mapping from type