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

/**
 * AD - Address<p>
 * This data type specifies the address of a person, place or organization.
 * <p>Represents an HL7 AD data type. 
 * This data type has the following attributes:</p><p>
 * 1.	street address (ST)<b>Optional</b><br>
 * 2.	other designation (ST)<b>Optional</b><br>
 * 3.	city (ST)<b>Optional</b><br>
 * 4.	state or province (ST)<b>Optional</b><br>
 * 5.	zip or postal code (ST)<b>Optional</b><br>
 * 6.	country (ID)<b>Optional</b><br>
 * 7.	address type (ID)<b>Optional</b><br>
 * 8.	other geographic designation (ST)<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 AD extends CompositeDataType   
{
	

	/**
	 * Default constructor for AD.
	 */
	public AD()
	{
		super(EnumDataType.HL7_DT_AD);
		 
	}
	/**
	 * Constructor for AD 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 AD(int iMinLength, int iMaxLength, String strCLength,int iComponentType) throws InvalidComponentTypeException
	{
		super(EnumDataType.HL7_DT_AD);
		this.iMinLength = iMinLength;
		this.iMaxLength = iMaxLength;
		this.iConformanceLength = strCLength;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}
	/**
	 * Constructor for AD 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.
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */
	public AD(int iMinLength, int iMaxLength, String strCLength,int iTableNo,int iComponentType)
	{
		super(EnumDataType.HL7_DT_AD);
		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 AD class which takes three 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 AD(int iComponentType,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_AD);
		this.objIDataTypeMap = objIDataTypeMap;
		this.iComponentType = iComponentType;

		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}
	/**
	 * Constructor for AD 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 AD(int iComponentType,int iMinLength, int iMaxLength, String strCLength,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_AD);
		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 AD class which takes six arguments and 
	 * sets the value in the respective member variable.
	 * @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. 
	 * @param objIDataTypeMap object of Data Type Map.
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */
	public AD(int iComponentType,int iMinLength, int iMaxLength, String strCLength,int ITableNo,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_AD);
		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 Street Address.
	 * @param strStreetAddress Specifies the street or mailing address of a person or institution.
	 */
	public void setStreetAddress(String strStreetAddress)
	{
		if(strStreetAddress!=null)
			setComponentType(1, strStreetAddress);
		else
			setStreetAddress((ST)null);
	}
	/**
	 * Sets the Street Address.
	 * @param objST object of Street Address.
	 */
	public void setStreetAddress(ST objST) 
	{
		setComponentType(1, objST);
	}
	/**
	 * Sets the Other Designation.
	 * @param strOtherDesignation Specifies the second line of address.
	 */
	public void setOtherDesignation(String strOtherDesignation)
	{
		if(strOtherDesignation!=null)
			setComponentType(2, strOtherDesignation);
		else
			setOtherDesignation((ST)null);
	}
	/**
	 * Sets the Other Designation.
	 * @param objST object of Other Designation.
	 */
	public void setOtherDesignation(ST objST) 
	{
		setComponentType(2, objST);
	}

	/**
	 * Sets the City.
	 * @param strCity Specifies the city, district or place where the addressee is located depending upon the national 
	 * 					convention for formatting addresses for postal usage.
	 */
	public void setCity(String strCity)
	{
		if(strCity!=null)
			setComponentType(3, strCity);
		else
			setCity((ST)null);
	}
	/**
	 * Sets the City.
	 * @param objST object of city, Specifies the city, district or place where the addressee is located depending upon the national 
	 * 					convention for formatting addresses for postal usage.
	 */
	public void setCity(ST objST) 
	{
		setComponentType(3, objST);
	}
	/**
	 * Sets the State Or Province.
	 * @param strStateOrProvince Specifies the state or province where the addressee is located.
	 */
	public void setStateOrProvince(String strStateOrProvince)
	{
		if(strStateOrProvince!=null)
			setComponentType(4, strStateOrProvince);
		else
			setStateOrProvince((ST)null);
	}
	/**
	 * Sets the State Or Province.
	 * @param objST object Specifies the state or province where the addressee is located.
	 */
	public void setStateOrProvince(ST objST) 
	{
		setComponentType(4, objST);
	}
	/**
	 * Sets the Zip Or Postal Code.
	 * @param strZipOrPostalCode Specifies the zip or postal code where the addressee is located.
	 */
	public void setZipOrPostalCode(String strZipOrPostalCode)
	{
		if(strZipOrPostalCode!=null)
			setComponentType(5, strZipOrPostalCode);
		else
			setZipOrPostalCode((ST)null);
	}
	/**
	 * Sets the Zip Or Postal Code.
	 * @param objST object Sets the Zip Or Postal Code.
	 */
	public void setZipOrPostalCode(ST objST) 
	{
		setComponentType(5, objST);
	}
	/**
	 * Sets the Country.
	 * @param strCountry Specifies the country where the addressee is located. Refer to HL7 Table 0399.
	 */
	public void setCountry(String strCountry)
	{
		if(strCountry!=null)
			setComponentType(6, strCountry);
		else
			setCountry((ID)null);
	}
	/**
	 * Sets the Country.
	 * @param objID object of Country.
	 */
	public void setCountry(ID objID)
	{
		setComponentType(6,objID);
	}
	/**
	 * Sets the Address Type.
	 * @param strAddressType Specifies the kind or type of address. Refer to HL7 Table 0190 - Address Type.
	 */
	public void setAddressType(String strAddressType)
	{
		if(strAddressType!=null)
			setComponentType(7, strAddressType);
		else
			setAddressType((ID)null);
	}
	/**
	 * Sets the Address Type.
	 * @param strAddressType Specifies the kind or type of address. Refer to HL7 Table 0190 - Address Type.
	 */
	public void setAddressType(ID objID)
	{
		setComponentType(7,objID);
	}
	/**
	 * Sets the Other Geographic Designation.
	 * @param strOtherGeographicDesignation Specifies any other geographic designation that may be necessary.
	 */
	public void setOtherGeographicDesignation(String strOtherGeographicDesignation)
	{
		if(strOtherGeographicDesignation!=null)
			setComponentType(8, strOtherGeographicDesignation);
		else
			setOtherGeographicDesignation((ST)null);
	}
	/**
	 * Sets the Other Geographic Designation.
	 * @param objST object Specifies any other geographic designation that may be necessary.
	 */
	public void setOtherGeographicDesignation(ST objST)
	{
		setComponentType(8,objST);
	}
	/**
	 * Returns Street Address. 
	 * @return ST - data type.
	 */
	public ST getStreetAddress()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(1);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Other Designation 
	 * @return ST - data type.
	 */
	public ST getOtherDesignation()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(2);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns City 
	 * @return ST - data type.
	 */
	public ST getCity() 
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(3);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns State or Province 
	 * @return ST - data type.
	 */
	public ST getStateOrProvince()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(4);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Zip or Postal Code 
	 * @return ST - data type.
	 */
	public ST getZipOrPostalCode()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(5);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Country 
	 * @return ID - data type.
	 */
	public ID getCountry()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(6);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Address Type 
	 * @return ID - data type.
	 */
	public ID getAddressType()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(7);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Other Geographic Designation 
	 * @return ST - data type.
	 */
	public ST getOtherGeographicDesignation()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(8);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)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 AD)))
			return false;

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

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

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

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

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

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

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

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

		return true;
	}
}
