/*******************************************************************************
 *  Copyright 2017-2018 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.dcm30_04.services.hangingprotocol.sourceimpl;

import cdac.medinfo.sdk.dcm30_04.baselibs.DataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITransferSyntax;
import cdac.medinfo.sdk.dcm30_04.services.dimsecommons.IQueryModel;
import cdac.medinfo.sdk.dcm30_04.utils.ICollectionIterator;
import cdac.medinfo.sdk.dcm30_04.utils.ISingleCollection;
import cdac.medinfo.sdk.dcm30_04.utils.SingleCollection;

/**
 *  This class represents Query Model for Hanging Protocol. This class contains methods to encode and decode Query Model.
 */
public class HangingProtocol_QueryModel implements IQueryModel
{
	ISingleCollection<HangingProtocol_Attributes> objHangingProtocol_AttributesList = null;
	
	/**
	 * This is default Constructor for HangingProtocol_QueryModel.
	 */
	public HangingProtocol_QueryModel()
	{
		this.objHangingProtocol_AttributesList = new SingleCollection<HangingProtocol_Attributes>();
	}
	
	/**
	 * Retrieve HangingProtocol Attributes list.
	 * @return ISingleCollection of HangingProtocol_Attributes
	 */
	public ISingleCollection<HangingProtocol_Attributes> getHangingProtocol_AttributesList() 
	{
		return objHangingProtocol_AttributesList;
	}

	/**
	 * To set the value of HangingProtocol Attributes List.
	 * @param objHangingProtocolAttributesList
	 */
	public void setHangingProtocol_AttributesList(ISingleCollection<HangingProtocol_Attributes> objHangingProtocolAttributesList) 
	{
		objHangingProtocol_AttributesList = objHangingProtocolAttributesList;
	}
	
	/**
	 * Populates the query Model using filled data set.
	 * @param objIDataSet Object of IDataSet.
	 * @return True - if Query Model populated successfully else False.
	 */
	public boolean decode(IDataSet objIDataSet)
	{
		if(this.objHangingProtocol_AttributesList == null)
			this.objHangingProtocol_AttributesList = new SingleCollection<HangingProtocol_Attributes>();
		
		HangingProtocol_Attributes objSubstanceAdministrationAttributesList = new HangingProtocol_Attributes();
		
		objSubstanceAdministrationAttributesList.populate(objIDataSet);
		
		objHangingProtocol_AttributesList.add(objSubstanceAdministrationAttributesList);
		return true;
	}
	
	
	/**
	 * Gets the filled DataSet list from already populated Query Model. 
	 * @param objITransferSyntax Object of ITransferSyntax. 
	 * @param objDataSetList Single collect of DataSet.
	 * @return True - Dataset List filled successfully else False.
	 */
	public boolean encode(ITransferSyntax objITransferSyntax, ISingleCollection<IDataSet> objDataSetList)
	{
		if(objHangingProtocol_AttributesList != null)
		{
			ICollectionIterator<HangingProtocol_Attributes> objHangingProtocol_AttributesIterator = objHangingProtocol_AttributesList.iterator();
			while(objHangingProtocol_AttributesIterator.hasNext())
			{
				HangingProtocol_Attributes objHangingProtocolAttributeList = objHangingProtocol_AttributesIterator.next();
				if(objHangingProtocolAttributeList != null)
				{
					IDataSet objIDataSet = new DataSet(objITransferSyntax);
					objHangingProtocolAttributeList.fill(objIDataSet);
					objDataSetList.add(objIDataSet);
				}
			}
			return true;
		}
		else
			return false;
	}
}
