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

import cdac.medinfo.sdk.hl7282.baselibs.messages.IMessageRecepient;
import cdac.medinfo.sdk.hl7282.baselibs.messages.Message_Source_Recepient;
import cdac.medinfo.sdk.hl7282.utils.EnumMessageCode;
import cdac.medinfo.sdk.hl7282.utils.EnumTriggerEvent;


/**
 * OrderEntryRecepient 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 final class OrderEntryRecepient extends Message_Source_Recepient implements IMessageRecepient  
{

	/**
	 * Constructs OrderEntryRecepient
	 */
	public OrderEntryRecepient()
	{
		super(OrderEntryMessageFactory.createInstance());
	}

	/**
	 * 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
	 */
	public boolean isMessageExtensionSupported(EnumMessageCode enumMsgCode,EnumTriggerEvent enumTriggerEvent)
	{
		return true;
	}

	/**
	 * 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
	 */
	public boolean canSend(EnumMessageCode enumMessageCode,EnumTriggerEvent enumTriggerEvent)
	{
		/*
		 * If enum trigger event is null then provided message code belongs to a locally extended message
		 * It simply checks whether this message code is supported or not.
		 */
		if(enumTriggerEvent == null)
			return canSend(enumMessageCode);
		
		switch(enumMessageCode)
		{
		case OMG:
		case OML:
		case OMI:
		case OMS:
		case OMD:
		case OMN:
		case OMP:
		case OMQ:
		case OMR:
		case RDE:
		case RDS:
		case RGV:
		case RAS:
		case VXU:
		case OMB:
		case BPS:
		case BTS:
		case OSR:
		case ORR:
		case ORG:
		case ORL:
		case OPL:
		case OPR:
		case ORI:
		case ORD:
		case ORS:
		case ORN:
		case ORP:
		case ORX:
		case OSU:
		case RRE:
		case RRD:
		case RRG:
		case RRA:
		case ROR:
		case RAR:
		case RDR:
		case RER:
		case RGR:
		case ORB:
		case BRP:
		case BRT:
		case RTB:
		case DBC:
		case DBU:
		case DEL:
		case DEO:
		case DER:
		case DPR:
		case DRC:
		case DRG:
		case VXX:
		case VXR:
			return true;
		case QBP:
		{
			switch(enumTriggerEvent)
			{
			case Q31:
				return true;
			case Q33:
				return true;
			case Q34:
				return true;
			}
		}
		break;
		case ACK:
		{
			if(objMessageFactory.isEventSupported(enumTriggerEvent))
				return true;
		}
		break;
		case RSP:
		{
			switch(enumTriggerEvent)
			{
			case K31:
				return true;
			case K33:
				return true;
			case K34:
				return true;
			}
		}
		break;
		}
		return false;
	}

	/**
	 * 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
	 */
	public boolean canReceive(EnumMessageCode enumMessageCode,EnumTriggerEvent enumTriggerEvent)
	{
		/*
		 * If enum trigger event is null then provided message code belongs to a locally extended message
		 * It simply checks whether this message code is supported or not.
		 */
		if(enumTriggerEvent == null)
			return canReceive(enumMessageCode);
		
		switch(enumMessageCode)
		{
		case ACK:
		{
			if(objMessageFactory.isEventSupported(enumTriggerEvent))
				return true;
		}
		break;
		case QBP:
		{
			switch(enumTriggerEvent)
			{
			case Q31:
				return true;
			case Q34:
				return true;
			case Q33:
				return true;
			}
		}
		break;
		case OSQ:
			return true;
		case VXQ:
			return true;
		}
		return false;
	}

	/*
	 * Checks whether underlying Message Recipient can send specified Message or not. 
	 * This method is specifically written for handling custom messages.
	 * When custom messages are to be sent, the decision is based on message code only.
	 * @param enumMessageCode specified message code.
	 * @return boolean status as true or false
	 */
	private boolean canSend(EnumMessageCode enumMessageCode)
	{
		switch(enumMessageCode)
		{
		case OMG:
		case OML:
		case OMI:
		case OMS:
		case OMD:
		case OMN:
		case OMP:
		case OMQ:
		case OMR:
		case RDE:
		case RDS:
		case RGV:
		case RAS:
		case VXU:
		case OMB:
		case BPS:
		case BTS:
		case OSR:
		case ORR:
		case ORG:
		case ORL:
		case OPL:
		case OPR:
		case ORI:
		case ORD:
		case ORS:
		case ORN:
		case ORP:
		case ORX:
		case OSU:
		case RRE:
		case RRD:
		case RRG:
		case RRA:
		case ROR:
		case RAR:
		case RDR:
		case RER:
		case RGR:
		case ORB:
		case BRP:
		case BRT:
		case RTB:
		case DBC:
		case DBU:
		case DEL:
		case DEO:
		case DER:
		case DPR:
		case DRC:
		case DRG:
		case QBP:
		case RSP:
		case VXX:
		case VXR:
		case ACK:
			return true;
		}
		return false;
	}

	/*
	 * Checks whether underlying Message Recipient can receive specified Message or not. 
	 * This method is specifically written for handling custom messages.
	 * When custom messages are to be sent, the decision is based on message code only.
	 * @param enumMessageCode specified message code.
	 * @return boolean status as true or false
	 */
	private boolean canReceive(EnumMessageCode enumMessageCode)
	{
		switch(enumMessageCode)
		{
		case ACK:
		case QBP:
		case OSQ:
		case VXQ:
			return true;
		}
		return false;
	}

}
