package it.enea.cruise.model.parametricQuery;


import java.util.List;

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

//import org.codehaus.jackson.annotate.JsonBackReference;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;


@Entity (name = "localqueryparameter")
@Table (name= "cruise.localqueryparameters")
public class LocalQueryParameter {
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="localqueryparameterid")
	private Long paramId;
	
	//@JsonIgnore
	//private Long queryid;
	
	private String description;

	private String name;
	
	private String type;
	
	private String example;
	
	private String familytype;
	
	private String inout;
	
	private String unitofmeasure;	
	
	@ManyToMany(mappedBy = "parameters")
	//@JsonBackReference(value = "parametricquery-parameter")
	@JsonIgnoreProperties("parameters")
	private List<ParametricQuery> parametricquery;
		
	public Long getParamId() {
		return paramId;
	}

	public void setParamId(Long paramId) {
		this.paramId = paramId;
	}

//	public Long getQueryid() {
//		return queryid;
//	}
//
//	public void setQueryid(Long queryid) {
//		this.queryid = queryid;
//	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getExample() {
		return example;
	}

	public void setExample(String example) {
		this.example = example;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getFamilytype() {
		return familytype;
	}

	public void setFamilytype(String familytype) {
		this.familytype = familytype;
	}

	public String getInout() {
		return inout;
	}

	public void setInout(String inout) {
		this.inout = inout;
	}

	public String getUnitofmeasure() {
		return unitofmeasure;
	}

	public void setUnitofmeasure(String unitofmeasure) {
		this.unitofmeasure = unitofmeasure;
	}
	
	

	
	public String getDescription(String language) {
		if (description.contains("|")) {
			String[] result = description.split(" \\| ");
			if (language.contains("it")) {
				return (result[0] + " | " + result[1]);
			} else {
				if (result.length > 2) {
					return (result[2] + " | " + result[3]);
				} else
					return (result[0] + " | " + result[1]);
			}
		} else
			return "";
	}

	public String getName() {
		return name;
	}

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