/*******************************************************************************
 *  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.ian.iansinkimpl;

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 NCreateIAN. This class contains methods to encode and decode Query Model.
 */
public class NCreateIAN_QueryModel implements IQueryModel
{
	ISingleCollection<NCreateIAN_Attributes> objNCreateIAN_AttributesList = null;
	
	public NCreateIAN_QueryModel()
	{
		this.objNCreateIAN_AttributesList = new SingleCollection<NCreateIAN_Attributes>();
	}
	
	public ISingleCollection<NCreateIAN_Attributes> getNCreateIAN_AttributesList() 
	{
		return objNCreateIAN_AttributesList;
	}

	public void setNCreateIAN_AttributesList(ISingleCollection<NCreateIAN_Attributes> objGPWLAttributesList) 
	{
		objNCreateIAN_AttributesList = objGPWLAttributesList;
	}
	
	/**
	 * Populates the Query Model using filled DataSet.
	 * @param objIDataSet Object of IDataSet.
	 * @return True - if Query Model populated successfully else False.
	 */
	public boolean decode(IDataSet objIDataSet)
	{
		if(this.objNCreateIAN_AttributesList == null)
			this.objNCreateIAN_AttributesList = new SingleCollection<NCreateIAN_Attributes>();
		
		NCreateIAN_Attributes objStudySAttributes = new NCreateIAN_Attributes();
		
		objStudySAttributes.populate(objIDataSet);
		
		objNCreateIAN_AttributesList.add(objStudySAttributes);
		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 - Data set List filled successfully else False.
	 */
	public boolean encode(ITransferSyntax objITransferSyntax, ISingleCollection<IDataSet> objDataSetList)
	{
		if(objNCreateIAN_AttributesList != null)
		{
			ICollectionIterator<NCreateIAN_Attributes> objNCreateIAN_AttributesIterator = objNCreateIAN_AttributesList.iterator();
			while(objNCreateIAN_AttributesIterator.hasNext())
			{
				NCreateIAN_Attributes objStudySAttributes = objNCreateIAN_AttributesIterator.next();
				if(objStudySAttributes != null)
				{
					IDataSet objIDataSet = new DataSet(objITransferSyntax);
					objStudySAttributes.fill(objIDataSet);
					objDataSetList.add(objIDataSet);
				}
			}
			return true;
		}
		else
			return false;
	}
}
