/*******************************************************************************
 *  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;

/**
 * CCP - Channel Calibration Parameters<p>
 * This data type identifies the corrections to channel sensitivity, the baseline, and the channel time skew when transmitting waveform results.
 * <p>Represents an HL7 CCP data type. 
 * This data type has the following attributes:</p><p>
 * 1. channel calibration sensitivity correction factor (NM)<b>Optional</b><br>
 * 2. channel calibration baseline (NM)<b>Optional</b><br>
 * 3. channel calibration time skew (NM)<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 CCP extends CompositeDataType    
{
	


	/**
	 * Default Constructor for CCP
	 */
	public CCP()
	{
		super(EnumDataType.HL7_DT_CCP);
	}

	/**
	 * Constructor  for CCP 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 CCP(int iMinLength, int iMaxLength, String strCLength,int iComponentType) throws InvalidComponentTypeException
	{
		super(EnumDataType.HL7_DT_CCP);
		this.iMinLength = iMinLength;
		this.iMaxLength = iMaxLength;
		this.iConformanceLength = strCLength;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}


	/**
	 * Constructor for CCP 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 CCP(int iMinLength, int iMaxLength, String strCLength,int iTableNo,int iComponentType) throws InvalidComponentTypeException
	{
		super(EnumDataType.HL7_DT_CCP);
		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 CCP 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 CCP(int iComponentType,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_CCP);
		this.objIDataTypeMap = objIDataTypeMap;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}
	/**
	 * Constructor for CCP 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 CCP(int iComponentType,int iMinLength, int iMaxLength, String strCLength,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_CCP);
		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 CCP 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 CCP(int iComponentType,int iMinLength, int iMaxLength, String strCLength,int ITableNo,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_CCP);
		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 Channel Calibration Sensitivity Correction Factor.
	 *@param strCCSCorrectionFactor Defines a correction factor for channel sensitivity 
	 */
	public void setChannelCalibrationSensitivityCorrectionFactor(String strCCSCorrectionFactor)
	{
		if(strCCSCorrectionFactor!=null)
			setComponentType(1, strCCSCorrectionFactor);
		else
			setChannelCalibrationSensitivityCorrectionFactor((NM)null);
	}

	/**
	 *Sets the Channel Calibration Sensitivity Correction Factor.
	 *@param objNM Defines a correction factor for channel sensitivity
	 */
	public void setChannelCalibrationSensitivityCorrectionFactor(NM objNM)
	{
		setComponentType(1,objNM);
	}

	/**
	 *Sets the Channel Calibration Baseline.
	 *@param strChannelCalibrationBaseline Defines the actual channel baseline 
	 */

	public void setChannelCalibrationBaseline(String strChannelCalibrationBaseline)

	{
		if(strChannelCalibrationBaseline!=null)
			setComponentType(2, strChannelCalibrationBaseline);
		else
			setChannelCalibrationBaseline((NM)null);
	}

	/**
	 *Sets the Channel Calibration Baseline.
	 *@param objNM Defines the actual channel baseline
	 */
	public void setChannelCalibrationBaseline(NM objNM)
	{
		setComponentType(2,objNM);
	}

	/**
	 *Sets the Channel Calibration Time Skew. 
	 *@param strChannelCalibrationTimeSkew Defines the time difference between the nominal sampling (digitization) time  
	 * 										  (which would be the same for all channels) and the actual sampling time of 
	 * 										  the channel, in seconds (or fractions thereof).
	 */
	public void setChannelCalibrationTimeSkew(String strChannelCalibrationTimeSkew)
	{
		if(strChannelCalibrationTimeSkew!=null)
			setComponentType(3, strChannelCalibrationTimeSkew);
		else
			setChannelCalibrationTimeSkew((NM)null);
	}

	/**
	 *Sets the Channel Calibration Time Skew. 
	 *@param objNM Defines the time difference between the nominal sampling (digitization) time  
	 * 										  (which would be the same for all channels) and the actual sampling time of 
	 * 										  the channel, in seconds (or fractions thereof).
	 */
	public void setChannelCalibrationTimeSkew(NM objNM)
	{
		setComponentType(3,objNM);
	}

	/**
	 * Returns Channel Calibration Sensitivity Correction Factor
	 * @return NM - data type.
	 */
	public NM getChannelCalibrationSensitivityCorrectionFactor()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(1);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Channel Calibration Baseline
	 * @return NM - data type.
	 */
	public NM getChannelCalibrationBaseline()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(2);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Channel Calibration Time Skew
	 * @return NM - data type.
	 */
	public NM getChannelCalibrationTimeSkew()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(3);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)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 CCP)))
			return false;

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

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

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

		return true;
	}
}
