package info.bukova.isspst.data;

import org.hibernate.annotations.Type;
import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * @author Pepa Rokos
 */
@Entity
@Table(name = "FILE_CONTENTS")
@Indexed
public class FileContent {

	@Id
	@Column(name = "ID")
	@GeneratedValue
	private int id;

	@Column(name = "CONTENT")
	@Type(type = "text")
	@Field(index = Index.YES, analyze = Analyze.YES)
	private String plainText;

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

	@Column(name = "PATH_IN_FILESYSTEM")
	private String pathInFilesystem;

	public int getId() {
		return id;
	}

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

	public String getPlainText() {
		return plainText;

	}

	public void setPlainText(String content) {
		this.plainText = content;
	}

	public String getContentType() {
		return contentType;
	}

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

	public String getPathInFilesystem() {
		return pathInFilesystem;
	}

	public void setPathInFilesystem(String pathInFilesystem) {
		this.pathInFilesystem = pathInFilesystem;
	}


	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (!(o instanceof FileContent)) return false;

		FileContent that = (FileContent) o;

		if (id != that.id) return false;
		if (plainText != null ? !plainText.equals(that.plainText) : that.plainText != null) return false;
		if (contentType != null ? !contentType.equals(that.contentType) : that.contentType != null) return false;
		if (pathInFilesystem != null ? !pathInFilesystem.equals(that.pathInFilesystem) : that.pathInFilesystem != null)
			return false;

		return true;
	}

	@Override
	public int hashCode() {
		int result = id;
		result = 31 * result + (plainText != null ? plainText.hashCode() : 0);
		result = 31 * result + (contentType != null ? contentType.hashCode() : 0);
		result = 31 * result + (pathInFilesystem != null ? pathInFilesystem.hashCode() : 0);
		return result;
	}
}
