/*******************************************************************************
 *  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.exceptions.InvalidDataTypeException;
import cdac.medinfo.sdk.hl7282.exceptions.MissingValueException;
import cdac.medinfo.sdk.hl7282.utils.EnumDataType;
import cdac.medinfo.sdk.hl7282.utils.IDataTypeMap;

/**
 * UVC - UB value code and amount<p>
 * This data type defines A code structure to 
 * relate amounts or values to identified data elements necessary to process 
 * this claim as qualified by the payer organization.
 * <p>Represents an HL7 UVC data type. 
 * This data type has the following attributes:</p><p>
 *  1. Value Code (CWE)<b>Required</b><br>
 *  2. Value Amount (MO)<b>Optional</b><br><p>
 *  3. Non-Monetary Value Amount / Quantity (NM)<b>Optional</b><br><p>
 *  4. Non-Monetary Value Amount / Units (CWE)<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 UVC extends CompositeDataType   
{
	


	/**
	 * Default Constructor for UVC
	 */
	public UVC()
	{
		super(EnumDataType.HL7_DT_UVC);
		 
	}

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


	/**
	 * Constructor for UVC 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 UVC(int iMinLength, int iMaxLength, String strCLength,int iTableNo,int iComponentType) throws InvalidComponentTypeException
	{
		super(EnumDataType.HL7_DT_UVC);
		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 UVC 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 UVC(int iComponentType,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_UVC);
		this.objIDataTypeMap = objIDataTypeMap;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}
	/**
	 * Constructor for UVC 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 UVC(int iComponentType,int iMinLength, int iMaxLength, String strCLength,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_UVC);
		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 UVC 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 UVC(int iComponentType,int iMinLength, int iMaxLength, String strCLength,int ITableNo,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_UVC);
		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 ValueCode.
	 * @param objValueCode Specifies the National Uniform Billing Committee (NUBC) code itself.
	 */
	public void setValueCode(CWE objValueCode)
	{
		setComponentType(1,objValueCode);
	}

	/**
	 * Sets the ValueAmount.
	 * @param objValueAmount Specifies the numeric amount when needed to pair with the value.
	 */
	public void setValueAmount(MO objValueAmount)
	{
		setComponentType(2,objValueAmount);
	}
	
	/**
	 *Sets the Non-Monetary Value Amount / Quantity.
	 *@param strNonMonetaryValueAmount Specifies the Numeric Amount. 
	 */
	public void setNonMonetaryValueAmountQuantity(String strNonMonetaryValueAmount)
	{
		if(strNonMonetaryValueAmount!=null)
			setComponentType(3, strNonMonetaryValueAmount);
		else
			setNonMonetaryValueAmountQuantity((NM)null);
	}


	/**
	 *Sets the Non-Monetary Value Amount / Quantity.
	 *@param objNM Specifies the Numeric Amount.
	 */
	public void setNonMonetaryValueAmountQuantity(NM objNM)
	{
		setComponentType(3,objNM);
	}
	
	/**
	 *Sets the Non-Monetary Value Amount / Units.
	 *@param strNonMonetaryValueAmount Specifies the Numeric Unit. 
	 */
	public void setNonMonetaryValueAmountUnits(String strNonMonetaryValueAmountUnits)
	{
		if(strNonMonetaryValueAmountUnits!=null)
			setComponentType(3, strNonMonetaryValueAmountUnits);
		else
			setNonMonetaryValueAmountUnits((CWE)null);
	}
	
	/**
	 *Sets the Non-Monetary Value Amount / Units.
	 *@param objCWE Specifies the Numeric Amount.
	 */
	public void setNonMonetaryValueAmountUnits(CWE objCWE)
	{
		setComponentType(4,objCWE);
	}

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

	/**
	 * Returns Value Amount
	 * @return MO - data type.
	 */
	public MO getValueAmount()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(2);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (MO)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Returns Non-Monetary Value Amount / Quantity
	 * @return CWE - data type.
	 */
	public CWE getNonMonetaryValueAmounQuantity()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(3);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Returns Non-Monetary Value Amount / Units
	 * @return CWE - data type.
	 */
	public CWE getNonMonetaryValueAmountUnits()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(4);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * The Method validates the Input value,and if validated properly then returns true.
	 * Here the validetion is based on the compulsory fields for the Datatype. 
	 * @return boolean - true or false.
	 * @throws InvalidDataTypeException - if Invalid values is entered or Mandatory field is missing. 
	 */
	public boolean validate() throws InvalidDataTypeException
	{
		super.validate();
		if(getComponentType(1)== null)
		{
			throw new MissingValueException(this.getClass().getSimpleName() + "Value Code");
		}
		else
			return true;
	}

	/**
	 * 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 UVC)))
			return false;

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

		if(this.getValueAmount() == null)
		{
			if(((UVC)objObject).getValueAmount() != null)
				return false;
		}
		else if(false == (this.getValueAmount().equals(((UVC)objObject).getValueAmount())))
			return false;
		
		if(this.getNonMonetaryValueAmounQuantity() == null)
		{
			if(((UVC)objObject).getNonMonetaryValueAmounQuantity() != null)
				return false;
		}
		else if(false == (this.getNonMonetaryValueAmounQuantity().equals(((UVC)objObject).getNonMonetaryValueAmounQuantity())))
			return false;
		
		if(this.getNonMonetaryValueAmountUnits() == null)
		{
			if(((UVC)objObject).getNonMonetaryValueAmountUnits() != null)
				return false;
		}
		else if(false == (this.getNonMonetaryValueAmountUnits().equals(((UVC)objObject).getNonMonetaryValueAmountUnits())))
			return false;

		return true;
	}
}
