/*******************************************************************************
 *  Copyright 2017 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 cdac.medinfo.sdk.hl7282.baselibs;

import cdac.medinfo.sdk.hl7282.baselibs.segmentfactory.DataElementFactory;
import cdac.medinfo.sdk.hl7282.commoninterface.IDataType;
import cdac.medinfo.sdk.hl7282.commoninterface.ISingleCollection;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidComponentTypeException;
import cdac.medinfo.sdk.hl7282.utils.EnumDataType;
import cdac.medinfo.sdk.hl7282.utils.IDataTypeMap;

/**
 * JCC - Job Code/Class<p>
 * This data type specifies person's job code/class.
 * <p>Represents an HL7 JCC data type. 
 * This data type has the following attributes:</p><p>
 *  1. Job Code (CWE)<b>Optional</b><br>
 *  2. Job Class (CWE)<b>Optional</b><br>
 *  3. Job Description Text (TX)<b>Optional</b><br><p>
 * This class provides accessors & mutators for the elements mentioned above.
 * This class override the equal method, to check whether some other object is "equal to" this one.
 * 
 * <p>User can also create Data Type through {@link DataElementFactory} 
 */
public class JCC extends CompositeDataType    
{
	

	/**
	 * Default Constructor for JCC
	 */
	public JCC()
	{
		super(EnumDataType.HL7_DT_JCC);
		 
	}

	/**
	 * Constructor  for JCC class which takes four arguments and 
	 * sets the value in the respective member variable.
	 * @param iMinLength The Minimum length the DataType can have.
	 * @param iMaxLength The Maximum length the DataType can have.
	 * @param iCLength The Conformance length the DataType can have.
	 * @param iComponentType The Type of the component i.e Component or a subcomponent.
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */ 
	public JCC(int iMinLength, int iMaxLength, String strCLength,int iComponentType) throws InvalidComponentTypeException
	{
		super(EnumDataType.HL7_DT_JCC);
		this.iMinLength = iMinLength;
		this.iMaxLength = iMaxLength;
		this.iConformanceLength = strCLength;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}

	/**
	 * Constructor for JCC class which takes five arguments and 
	 * sets the value in the respective member variable.
	 * @param iMinLength The Minimum length the DataType can have.
	 * @param iMaxLength The Maximum length the DataType can have.
	 * @param iCLength The Conformance length the DataType can have.
	 * @param iTableNo The Table number to which the value for the component is specified. 
	 * @param iComponentType The Type of the component i.e Component or a subcomponent.
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */
	public JCC(int iMinLength, int iMaxLength, String strCLength,int iTableNo,int iComponentType) throws InvalidComponentTypeException
	{
		super(EnumDataType.HL7_DT_JCC);
		this.iMinLength = iMinLength;
		this.iMaxLength = iMaxLength;
		this.iConformanceLength = strCLength;
		this.iTableNo = iTableNo;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());		
		}
	}
	/**
	 * Constructor for JCC class which takes two arguments and 
	 * sets the value in the respective member variable.
	 * @param objIDataTypeMap object of Data Type Map.
	 * @param iComponentType The Type of the component i.e Component or a subcomponent.
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */
	public JCC(int iComponentType,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_JCC);
		this.objIDataTypeMap = objIDataTypeMap;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}
	/**
	 * Constructor for JCC class which takes five arguments and 
	 * sets the value in the respective member variable.
	 * @param objIDataTypeMap object of Data Type Map.
	 * @param iComponentType The Type of the component i.e Component or a subcomponent.
	 * @param iMinLength The Minimum length the DataType can have.
	 * @param iMaxLength The Maximum length the DataType can have.
	 * @param iCLength The Conformance length the DataType can have.
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */
	public JCC(int iComponentType,int iMinLength, int iMaxLength, String strCLength,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_JCC);
		this.objIDataTypeMap = objIDataTypeMap;
		this.iComponentType = iComponentType;
		this.iMinLength = iMinLength;
		this.iMaxLength = iMaxLength;
		this.iConformanceLength = strCLength;

		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}
	/**
	 * Constructor for JCC class which takes six arguments and 
	 * sets the value in the respective member variable.
	 * @param objIDataTypeMap object of Data Type Map.
	 * @param iComponentType The Type of the component i.e Component or a subcomponent.
	 * @param iMinLength The Minimum length the DataType can have.
	 * @param iMaxLength The Maximum length the DataType can have.
	 * @param iCLength The Conformance length the DataType can have.
	 * @param iTableNo The Table number to which the value for the component is specified. 
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */
	public JCC(int iComponentType,int iMinLength, int iMaxLength, String strCLength,int ITableNo,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_JCC);
		this.objIDataTypeMap = objIDataTypeMap;
		this.iComponentType = iComponentType;
		this.iTableNo = ITableNo;
		this.iMinLength = iMinLength;
		this.iMaxLength = iMaxLength;
		this.iConformanceLength = strCLength;

		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}

	/**
	 *Sets the JobCode.
	 *@param strJobCode contains the persons job code.  
	 */
	public void setJobCode(String strJobCode)
	{
		if(strJobCode!=null)
			setComponentType(1, strJobCode);
		else
			setJobCode((CWE)null);
	}

	/**
	 *Sets the JobClass.
	 *@param strJobClass contains the persons employee classification.  
	 */
	public void setJobClass(String strJobClass)
	{
		if(strJobClass!=null)
			setComponentType(2, strJobClass);
		else
			setJobClass((CWE)null);
	}
	/**
	 *Sets the JobCode.
	 *@param objCWE contains the person's job code. 
	 */
	public void setJobCode(CWE objCWE)
	{
		setComponentType(1,objCWE);
	}

	/**
	 *Sets the JobClass.
	 *@param objCWE contains the person's employee classification. 
	 */
	public void setJobClass(CWE objCWE)
	{
		setComponentType(2,objCWE);
	}

	/**
	 *Sets the JobDescriptionText.
	 *@param strJobDescriptionText contains the text of the job description. 
	 */
	public void setJobDescriptionText(String strJobDescriptionText)
	{
		if(strJobDescriptionText!=null)
			setComponentType(3, strJobDescriptionText);
		else
			setJobDescriptionText((TX)null);
	}

	/**
	 *Sets the JobDescriptionText.
	 *@param objTX contains the text of the job description.
	 */
	public void setJobDescriptionText(TX objTX)
	{
		setComponentType(3,objTX);
	}

	/**
	 * Returns Job Code
	 * @return CWE - data type.
	 */
	public CWE getJobCode()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(1);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Job Class
	 * @return CWE - data type.
	 */
	public CWE getJobClass()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(2);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Job Description Text
	 * @return TX - data type.
	 */
	public TX getJobDescriptionText()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(3);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (TX)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * This method checks the equality of Object.
	 * @param objObject object of Object class.
	 * @return boolean - shows success or failure of the comparison.
	 */
	public boolean equals(Object objObject)
	{
		if((objObject == null ) || (!(objObject instanceof JCC)))
			return false;

		if(this.getJobCode() == null)
		{
			if(((JCC)objObject).getJobCode() != null)
				return false;
		}
		else if(false == (this.getJobCode().equals(((JCC)objObject).getJobCode())))
			return false;

		if(this.getJobClass() == null)
		{
			if(((JCC)objObject).getJobClass() != null)
				return false;
		}
		else if(false == (this.getJobClass().equals(((JCC)objObject).getJobClass())))
			return false;

		if(this.getJobDescriptionText() == null)
		{
			if(((JCC)objObject).getJobDescriptionText() != null)
				return false;
		}
		else if(false == (this.getJobDescriptionText().equals(((JCC)objObject).getJobDescriptionText())))
			return false;

		return true;
	}
}
