/*******************************************************************************
 *  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.mwl.mwlsourceimpl;

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 MWL. This class contains methods to encode and decode Query Model.
 */
public class MWL_QueryModel implements IQueryModel
{
	ISingleCollection<MWL_Attributes> objMWL_AttributesList = null;
	
	public MWL_QueryModel()
	{
		this.objMWL_AttributesList = new SingleCollection<MWL_Attributes>();
	}
	
	public ISingleCollection<MWL_Attributes> getMWL_AttributesList() 
	{
		return objMWL_AttributesList;
	}

	public void setMWL_AttributesList(ISingleCollection<MWL_Attributes> objMWLAttributesList) 
	{
		objMWL_AttributesList = objMWLAttributesList;
	}
	
	/**
	 * 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.objMWL_AttributesList == null)
			this.objMWL_AttributesList = new SingleCollection<MWL_Attributes>();
		
		MWL_Attributes objMwlAttributes = new MWL_Attributes();
		
		objMwlAttributes.populate(objIDataSet);
		
		objMWL_AttributesList.add(objMwlAttributes);
		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(objMWL_AttributesList != null)
		{
			ICollectionIterator<MWL_Attributes> objMWL_AttributesIterator = objMWL_AttributesList.iterator();
			while(objMWL_AttributesIterator.hasNext())
			{
				MWL_Attributes objMwlAttributes = objMWL_AttributesIterator.next();
				if(objMwlAttributes != null)
				{
					IDataSet objIDataSet = new DataSet(objITransferSyntax);
					objMwlAttributes.fill(objIDataSet);
					objDataSetList.add(objIDataSet);
				}
			}
			return true;
		}
		else
			return false;
	}
}
