package info.bukova.isspst.data;

import info.bukova.isspst.Constants;
import info.bukova.isspst.reporting.Report;
import info.bukova.isspst.reporting.ReportMapping;

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

@Entity
@Table(name = "SIGNED_DOCUMENTS_ITEMS")
public class SignedDocumentItem {

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

	@Column(name = "REPORT_ID")
	private long reportId;

	@Column(name = "REPORT_NAME", length = Constants.LEN_TEXT)
	private String reportName;

	@Column(name = "FILENAME", length = Constants.LEN_TEXT)
	private String fileName;

	@ManyToOne
	@JoinColumn(name = "SIGNED_DOCUMENT_ID")
	private SignedDocument signedDocument;

	public int getId() {
		return id;
	}

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

	public long getReportId() {
		return reportId;
	}

	public void setReportId(long reportId) {
		this.reportId = reportId;
	}

	public String getReportName() {
		return reportName;
	}

	public void setReportName(String reportName) {
		this.reportName = reportName;
	}

	public String getActualReportName() {
		for (ReportMapping rm : Constants.REPORTS) {
			Report rep = rm.getReport();

			if (this.reportId == rep.getReportId()) {
				return rep.getName();
			}
		}

		return reportName;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public SignedDocument getSignedDocument() {
		return signedDocument;
	}

	public void setSignedDocument(SignedDocument signedDocument) {
		this.signedDocument = signedDocument;
	}
}
