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

import java.io.IOException;

import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLStreamException;

import cdac.medinfo.sdk.hl7282.exceptions.GroupMissingException;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidMessageException;
import cdac.medinfo.sdk.hl7282.utils.IMap;

/**
 * This is Parent Interface of Group in Model layer.
 * Provides the contract that the implementor Group should follow.
 */
public interface IGroup 
{
	/**
	 * Populates the Segment Set.
	 * @return int - return HL7_FUNCTION_SUCCESS after success.
	 * @throws GroupMissingException
	 */
	int populate(ISegmentSet objSegmentSet) throws GroupMissingException;
	
	/**
	 * Adds segment in multi valued paired collection.
	 * @param enumSegments Key that is to be added to collection
	 * @param objSegment Value of the key.
	 */
	void addSegment(ISegmentKey enumSegments , ISegment objSegment);
	
	/**
	 * Adds the group in Collection of data value.
	 * @param enumSegments - object of enumSegment .
	 * @param objGroup - object of Group.
	 */
	void addGroup(ISegmentKey enumSegments ,IGroup objGroup);
	
	/**
	 * Sets the name of group.
	 * @param enumName - object of enumName.
	 */
	void setName(ISegmentKey enumName);
	
	/**
	 * Return SegmentKey.
	 * @return SegmentKey.
	 */
	ISegmentKey getName();
	
	/**
	 * Retrieves all segments present in this group
	 * @return ISingleCollection<ISegment> - List of Segments
	 */
	ISegmentSet getSegmentSet()throws InvalidMessageException;
	
	/**
	 * Retrieves collection of ISegment.
	 * @return ISingleCollection<ISegment> -return collection of ISegment.
	 */
	ISingleCollection<ISegment> getSegmentCollection();
	
	/**
	 *Gives collection of group of name enumGroup as passed by user.
	 * @param enumGroup Name of group.
	 * @return ISingleCollection<Group> - Collection of Group .
	 */
	ISingleCollection<IGroup> getGroup(ISegmentKey enumGroup);
	
	/**
	 * Gives collection of segment of name enumSegments as passed by user.
	 * @param enumSegments Name of Segment.
	 * @return ISingleCollection<Segment> - Collection of Segments .
	 */
	ISingleCollection<ISegment> getSegment(ISegmentKey enumSegments);
	
	/**
	 * Validates HL7 Message objects.
	 * Validate method checks for validation each and every segments in side the Message object against specified message Structure. 
	 * Validation checks include optionality of segment or group.
	 * It also verifies the number of times segment or group is repeated in message.
	 * e.g 
	 * {PSH} while parsing PSH segment validate method will check for its mandatory presence.
	 * [PSH] in this case validate will throw exception if one tries to enter more than one PSH segment.    
	 * @return boolean - true If Message and all segments in side it are validated properly 
	 *				   - false If segment in side it is not validated properly and if compulsory segments are not present.
	 *@throws InvalidMessageException Thrown when Message validation fails.
	 */
	boolean validate() throws InvalidMessageException;
	
	/**
	 * Uses to write to XML 
	 * @param eventWriter object of eventWriter.
	 * @return int - return integer 
	 */
	int writeToXML(XMLEventWriter eventWriter) throws IOException, XMLStreamException;
	
	/**
	 * Uses to write to XML 
	 * @param eventWriter object of eventWriter.
	 * @param messageType contains message Structure
	 * @return int - return integer 
	 * @throws IOException
	 * @throws XMLStreamException
	 */
	int writeToXML_v2(XMLEventWriter eventWriter,String messageType) throws IOException, XMLStreamException;
	
	/**
	 * Returns the size of the group
	 * @return int - return size.
	 */
	int size();
	
	/**
	 * Retrieves Map of specified Group name.
	 * @param enumGroupName Object of ISegmentKey provides name of Group
	 * @return IMessageMap Object of IMessageMap
	 */
	IMap getGroupMap(ISegmentKey enumGroupName);
}
