/*******************************************************************************
 * Copyright 2014 Centre for Development of Advanced Computing(C-DAC), Pune
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package in.cdac.medinfo.csnotk.csnolib.model;

import in.cdac.medinfo.csnotk.csnolib.commons.EnumCaseSignificance;
import in.cdac.medinfo.csnotk.csnolib.commons.EnumDescType;

import java.io.Serializable;
import java.util.Date;

/**
 * Description is a human readable text of a concept. 
 * 
 */
public class Description extends Component implements Serializable
{
	/**
	 * Default serial version UID.
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * conceptId represents the concept Id of the concept associated with that particular 
	 * description.
	 */
	private String conceptId;
	/**
	 * languageCode specifies the language used in the description text.
	 */
	private String languageCode;
	/**
	 * typeId represents the id that specifies the description type.
	 */
	private EnumDescType typeId;
	/**
	 * Represents the Description term.
	 */
	private String term;
	/**
	 * caseSignificanceId represents the significance of case in the Description.
	 */
	private EnumCaseSignificance caseSignificanceId;
	
	/**
	 * Default constructor.
	 */
	protected Description()
	{
		
	}
	/**
	 * Parameterized constructor.
	 * @param id
	 * 			 represents the Description id.
	 * @param effTime
	 * 			 represents effective Time associated with that Description.
	 * @param status
	 * 			 represents the active Status of the description. It can be active
	 * 			 or inactive (0 or 1).
	 * @param modId
	 * 			 represents the module Id.
	 * @param conceptId
	 * 			 represents the concept Id associated with a particular Description.
	 * @param langCode
	 * 			 represents the language used in the description text.
	 * @param typeId
	 * 			 Id that represents the type of the Description.
	 * @param term
	 * 			 represents the Description text.
	 * @param caseSId
	 * 			 represents the case significance id.
	 */
	protected Description(String id,Date effTime,Byte status,String modId,
			String conceptId,String langCode,EnumDescType typeId,
			String term,EnumCaseSignificance caseSId)
	{
		super(id,effTime,status,modId);
		this.conceptId=conceptId;
		this.languageCode=langCode;
		this.typeId=typeId;
		this.term=term;
		this.caseSignificanceId=caseSId;
	}

	public static final String FSN_TYPE = "900000000000003001";
	
	/**
	 * Returns the Description Id.
	 * @return SNOMED CT identifier of the description.
	 */
	public String getId() {
		return super.getId();
	}
	/**
	 * sets SNOMED CT identifier of the description.
	 * @param id
	 * 			 represents Description id.
	 */
	public void setId(String id) {
		super.setId(id);
	}
	/**
	 * Returns the status of the Description(active or inactive).
	 */
	public Byte getActiveStatus() {
		return super.getActiveStatus();
	}
	/**
	 * Sets the status of the Description(active or inactive).
	 */
	public void setActiveStatus(Byte status) {
		super.setActiveStatus(status);
	}
	/**
	 * Returns the module Id for the Description.
	 */
	public String getModuleId()
	 {
		 return super.getModuleId();
	 }
	/**
	 * Sets the module Id for the Description.
	 */
	 public void setModuleId(String modId)
	 {
		 super.setModuleId(modId);
	 }
	 /**
	  * Returns the effective time for the Description.
	  */
	 public Date getTime()
	 {
		 return super.getTime();
	 }
	 /**
	  * Sets the effective time for the Description.
	  */
	 public void setTime(Date date)
	 {
		 super.setTime(date);
	 }
	 /**
	  * Returns the languageCode.languageCode that specifies
	  *  the language for the description text.
	  */
	public String getLangCode()
	{
		return this.languageCode;
	}
	/**
	  * Sets the language Code for the Description.
	  */
	public void setLangCode(String langCode)
	{
		this.languageCode=langCode;
	}
	/**
	 * Returns the Id that represents the case significance of the Description text.
	 * @return caseSignificanceId
	 */
	public String getCaseSId()
	{
		return this.caseSignificanceId.getValue();
	}
	/**
	 * Sets the caseSignificanceId of the description.
	 * @param caseSId
	 * 				 caseSignificance Id that defines the case sensitiveness of the 
	 * 				 Description text.
	 */
	public void setCaseSId(EnumCaseSignificance caseSId)
	{
		this.caseSignificanceId=caseSId;
	}
	/**
	 * Returns the Concept Id.
	 * @return the identifier of the associated {@link Concept} described.
	 */
	public String getConceptId() {
		return conceptId;
	}
	/**
	 * Sets the Concept Id attribute of the description.
	 */
	public void setConceptId(String conceptId) {
		this.conceptId = conceptId;
	}
	
	/**
	 * Returns the term corresponding to the Description.
	 * @return the textual description of the associated {@link Concept}.
	 */
	public String getTerm() {
		return term;
	}
	/**
	 * Sets the term for the Description.
	 * @param term
	 * 				 The description text for a particular Description.
	 */
	public void setTerm(String term) {
		this.term = term;
	}
	
	/**
	 * Returns Description type.
	 * @return the type of the description i.e. if the description is either an FSN or a synonym.
	 */
	public String getType() {
		return typeId.getValue();
	}
	/**
	 * Sets the typeId associated with the Description.
	 * @param type
	 * 				the type of the Description. It can be FSN or Synonym.
	 */
	public void setType(EnumDescType type) {
		this.typeId = type;
	}
	
	@Override
	public String toString(){
		return getTerm();
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
	//	result = prime * result + ((conceptId == null) ? 0 : conceptId.hashCode());//(int) (conceptId ^ (conceptId >>> 32));
		result = prime * result + ((id == null) ? 0 : id.hashCode());
	//	result = prime * result + ((term == null) ? 0 : term.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {		
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Description other = (Description) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;		
		return true;
	}
}
