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

import cdac.medinfo.sdk.hl7282.commoninterface.ISegmentSet;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidMessageException;
import cdac.medinfo.sdk.hl7282.exceptions.MessageNotSupportedException;
import cdac.medinfo.sdk.hl7282.utils.EnumMessageCode;
import cdac.medinfo.sdk.hl7282.utils.EnumTriggerEvent;

/**
 * IMessageRecepient provides methods to parse message from Given HL7stream object.It supports check for Query messages.
 * Unlike Message Processor it does not support creation of Message.With implementor of this interface you can not trigger event.
 * But you can process event.It also has support for creation of Queries. 
 */
public interface IMessageRecepient 
{
	/**
	 * Checks whether underlying Message Recipient supports extension of message for provided message code and trigger event.
	 * For Local trigger events enum value must be null.
	 * @param enumMsgCode specified message code.
	 * @param enumTriggerEvent specified trigger event
	 * @return boolean status as true or false
	 */
	boolean isMessageExtensionSupported(EnumMessageCode enumMsgCode,EnumTriggerEvent enumTriggerEvent);
	
	/**
	 * Checks whether underlying Message Recipient can send specified Message or not.
	 * @param enumMessageCode specified message code
	 * @param enumTriggerEvent specified trigger event
	 * @return boolean status as true or false
	 */
	boolean canSend(EnumMessageCode enumMessageCode,EnumTriggerEvent enumTriggerEvent);
	
	/**
	 * Checks whether underlying Message Recipient can receive specified Message or not.
	 * @param enumMessageCode specified message code
	 * @param enumTriggerEvent specified trigger event
	 * @return boolean status as true or false
	 */
	boolean canReceive(EnumMessageCode enumMessageCode,EnumTriggerEvent enumTriggerEvent);
	
	/**
	 * Creates Empty Message with Message Structure & Trigger Event specified.
	 * @param enumMessageCode specified message code
	 * @param enumTriggerEvent specified trigger event
	 * @return Message - Generated Empty Message
	 * @throws MessageNotSupportedException Thrown when Message creation is not supported by HL7 SDK
	 */
	public Message createMessage(EnumMessageCode enumMessageCode,EnumTriggerEvent enumTriggerEvent) throws MessageNotSupportedException;
	
	/**
	 * Parses Message from HL7 Stream.  
	 * @param objISegmentSet Stream from which Message to be parsed
	 * @return Message- message parsed
	 * @throws MessageNotSupportedException Thrown when Message creation is not supported by HL7 SDK
	 * @throws InvalidMessageException if Message validation fails 
	 */
	public Message populateMessage(ISegmentSet objISegmentSet) throws MessageNotSupportedException,InvalidMessageException;
	
	/**
	 * Parses Message with Specified Message Structure & Message Trigger Event from HL7 Stream.  
	 * @param enumMessageCode specified message code
	 * @param enumTriggerEvent specified trigger event
	 * @param objISegmentSet Stream from which Message to be parsed
	 * @return Message- message parsed
	 * @throws MessageNotSupportedException Thrown when Message creation is not supported by HL7 SDK
	 * @throws InvalidMessageException if Message validation fails
	 */
	public Message populateMessage(EnumMessageCode enumMessageCode,EnumTriggerEvent enumTriggerEvent, ISegmentSet objISegmentSet) throws MessageNotSupportedException,InvalidMessageException;
}
