package cdac.medinfo.sdk.hl7282.hl7model.messages.materialsmanagement;

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;

public final class MaterialsMgtRecepient extends Message_Source_Recepient implements IMessageRecepient
{
	/**
	 * Constructs MaterialsMgtRecepient
	 */
	public MaterialsMgtRecepient()
	{
		super(MaterialsMgtMessageFactory.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 SLR: 
		case STI:
		case SDR:
		case SMD:
		case STC:
		case SLN:
		case SDN:
		case SCN:
			return true;
		case ACK:
		{
			if(objMessageFactory.isEventSupported(enumTriggerEvent))
				return true;
		}
		break;
		}
		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 SLR: 
		case STI:
		case SDR:
		case SMD:
		case STC:
		case SLN:
		case SDN:
		case SCN:
		case ACK:
			return true;
		}
		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;
		}
		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:
			return true;
		}
		return false;
	}

}
