package eu.stork.documentservice.model;

import java.util.Date;

import eu.stork.documentservice.exceptions.ModelException;

/**
 * The request model class
 * @author sveinbjorno
 *
 */
public class RequestModel {

	private String requestid;
	private String docid;
	private String destcountry;
	private String spcountry;
	private String spid;
	private String xmlrequest;
	private String xmlresponse;
	private Date reqtimestamp;
	private Date restimestamp;
	
	public String getRequestid() {
		return requestid;
	}
	public void setRequestid(String requestid) {
		this.requestid = requestid;
	}
	public String getDocid() {
		return docid;
	}
	public void setDocid(String docid) {
		this.docid = docid;
	}
	public String getDestcountry() {
		return destcountry;
	}
	public void setDestcountry(String destcountry) {
		this.destcountry = destcountry;
	}
	public String getSpcountry() {
		return spcountry;
	}
	public void setSpcountry(String spcountry) {
		this.spcountry = spcountry;
	}
	public String getSpid() {
		return spid;
	}
	public void setSpid(String spid) {
		this.spid = spid;
	}
	public String getXmlrequest() {
		return xmlrequest;
	}
	public void setXmlrequest(String xmlrequest) {
		this.xmlrequest = xmlrequest;
	}
	public String getXmlresponse() {
		return xmlresponse;
	}
	public void setXmlresponse(String xmlresponse) {
		this.xmlresponse = xmlresponse;
	}
	public Date getReqtimestamp() {
		return reqtimestamp;
	}
	public void setReqtimestamp(Date reqtimestamp) {
		this.reqtimestamp = reqtimestamp;
	}
	public Date getRestimestamp() {
		return restimestamp;
	}
	public void setRestimestamp(Date restimestamp) {
		this.restimestamp = restimestamp;
	}
	
	public String getFullDocID()
	{
		return this.spcountry + "/" + this.destcountry + "/" + this.docid;
	}
	
	public void insertValidate() throws ModelException
	{		
		if (this.requestid == null || this.requestid.isEmpty())
			throw new ModelException("Request ID is null or empty");		
		if (this.destcountry == null || this.destcountry.isEmpty())
			throw new ModelException("Destination country is null or empty.");
		if (this.spcountry == null || this.spcountry.isEmpty())
			throw new ModelException("SP country is null or empty.");
		if (this.destcountry == null || this.destcountry.isEmpty())
			throw new ModelException("Destination country is null or empty.");
		if (this.xmlrequest== null || this.xmlrequest.isEmpty())
			throw new ModelException("XML request is null or empty.");
	}
	
	public void updateValidate() throws ModelException
	{
		this.insertValidate();
		if (this.docid == null || this.docid.isEmpty())
			throw new ModelException("Document ID is null or empty");
		if (this.reqtimestamp == null)
			throw new ModelException("Request timestamp is null or empty");
	}
}