/*
 * Copyright 2017 EPAM Systems
 *
 *
 * This file is part of EPAM Report Portal.
 * https://github.com/reportportal/service-api
 *
 * Report Portal is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Report Portal is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Report Portal.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.epam.ta.reportportal.entity.log;

import com.epam.ta.reportportal.entity.item.TestItem;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

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

/**
 * @author Pavel Bortnik
 */

@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "log", schema = "public", indexes = { @Index(name = "log_pk", unique = true, columnList = "id ASC") })
public class Log implements Serializable {

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

	@Column(name = "log_time", nullable = false)
	private LocalDateTime logTime;

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

	@LastModifiedDate
	@Column(name = "last_modified", nullable = false)
	private LocalDateTime lastModified;

	@Column(name = "log_level", nullable = false, precision = 32)
	private Integer logLevel;

	@ManyToOne
	@JoinColumn(name = "item_id")
	private TestItem testItem;

	@Column(name = "file_path")
	private String filePath;

	@Column(name = "thumbnail_file_path")
	private String thumbnailFilePath;

	@Column(name = "content_type")
	private String contentType;

	public Log(Long id, LocalDateTime logTime, String logMessage, LocalDateTime lastModified, Integer logLevel, TestItem testItem,
			String filePath, String thumbnailFilePath, String contentType) {
		this.id = id;
		this.logTime = logTime;
		this.logMessage = logMessage;
		this.lastModified = lastModified;
		this.logLevel = logLevel;
		this.testItem = testItem;
		this.filePath = filePath;
		this.thumbnailFilePath = thumbnailFilePath;
		this.contentType = contentType;
	}

	public Log() {
	}

	public Long getId() {
		return id;
	}

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

	public TestItem getTestItem() {
		return testItem;
	}

	public void setTestItem(TestItem testItem) {
		this.testItem = testItem;
	}

	public LocalDateTime getLogTime() {
		return logTime;
	}

	public void setLogTime(LocalDateTime logTime) {
		this.logTime = logTime;
	}

	public LocalDateTime getLastModified() {
		return lastModified;
	}

	public void setLastModified(LocalDateTime lastModified) {
		this.lastModified = lastModified;
	}

	public String getLogMessage() {
		return logMessage;
	}

	public void setLogMessage(String logMessage) {
		this.logMessage = logMessage;
	}

	public Integer getLogLevel() {
		return logLevel;
	}

	public void setLogLevel(Integer logLevel) {
		this.logLevel = logLevel;
	}

	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	public String getThumbnailFilePath() {
		return thumbnailFilePath;
	}

	public void setThumbnailFilePath(String thumbnailFilePath) {
		this.thumbnailFilePath = thumbnailFilePath;
	}

	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (o == null || getClass() != o.getClass()) {
			return false;
		}
		Log log = (Log) o;
		return Objects.equals(id, log.id) && Objects.equals(logTime, log.logTime) && Objects.equals(logMessage, log.logMessage)
				&& Objects.equals(lastModified, log.lastModified) && Objects.equals(logLevel, log.logLevel) && Objects.equals(testItem,
				log.testItem
		);
	}

	@Override
	public int hashCode() {
		return Objects.hash(id, logTime, logMessage, lastModified, logLevel, testItem);
	}

	@Override
	public String toString() {
		return "Log{" + "id=" + id + ", logTime=" + logTime + ", logMessage='" + logMessage + '\'' + ", lastModified=" + lastModified
				+ ", logLevel=" + logLevel + '}';
	}
}

@@ -1977,25 +1977,26 @@
 name = %22
-file_path
+attachment
 %22)%0A%09priv
@@ -2006,24 +2006,26 @@
  String 
-filePath
+attachment
 ;%0A%0A%09@Col
@@ -2040,63 +2040,66 @@
  = %22
-thumbnail_file_path%22)%0A%09private String thumbnailFilePath
+attachment_thumbnail%22)%0A%09private String attachmentThumbnail
 ;%0A%0A%09
@@ -2301,42 +2301,46 @@
 ing 
-filePath, String thumbnailFilePath
+attachment, String attachmentThumbnail
 , St
@@ -2536,73 +2536,81 @@
 his.
-filePath = filePath;%0A%09%09this.thumbnailFilePath = thumbnailFilePath
+attachment = attachment;%0A%09%09this.attachmentThumbnail = attachmentThumbnail
 ;%0A%09%09
@@ -3487,24 +3487,26 @@
 ring get
-FilePath
+Attachment
 () %7B%0A%09%09r
@@ -3511,24 +3511,26 @@
 %09return 
-filePath
+attachment
 ;%0A%09%7D%0A%0A%09p
@@ -3547,62 +3547,70 @@
  set
-FilePath(String filePath) %7B%0A%09%09this.filePath = filePath
+Attachment(String attachment) %7B%0A%09%09this.attachment = attachment
 ;%0A%09%7D
@@ -3629,16 +3629,26 @@
 ring get
+Attachment
 Thumbnai
@@ -3648,24 +3648,16 @@
 humbnail
-FilePath
 () %7B%0A%09%09r
@@ -3662,33 +3662,35 @@
 %09return 
-thumbnailFilePath
+attachmentThumbnail
 ;%0A%09%7D%0A%0A%09p
@@ -3707,98 +3707,106 @@
  set
-ThumbnailFilePath(String thumbnailFilePath) %7B%0A%09%09this.thumbnailFilePath = thumbnailFilePath
+AttachmentThumbnail(String attachmentThumbnail) %7B%0A%09%09this.attachmentThumbnail = attachmentThumbnail
 ;%0A%09%7D

update Log table