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

import cdac.medinfo.sdk.hl7282.baselibs.ID;
import cdac.medinfo.sdk.hl7282.baselibs.NM;
import cdac.medinfo.sdk.hl7282.baselibs.ST;
import cdac.medinfo.sdk.hl7282.commoninterface.IDataType;
import cdac.medinfo.sdk.hl7282.commoninterface.ISingleCollection;
import cdac.medinfo.sdk.hl7282.exceptions.FieldMissingException;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidSegmentException;
import cdac.medinfo.sdk.hl7282.utils.EnumSegments;

/**
 * MSA -  Message Acknowledgment Segment.<p>
 * The MSA segment contains information sent while acknowledging another message. 
 * <p>Represents an HL7 MSA message segment. 
 * This segment has the following fields:</p><p>
 * MSA-1: Acknowledgment Code (ID)<b>Required</b><br> 
 * MSA-2: Message Control ID (ST)<b>Required</b><br> 
 * MSA-3: Text Message (ST)<b>Withdrawn</b><br> 
 * MSA-4: Expected Sequence Number (NM)<b>Optional</b><br> 
 * MSA-5: Delayed Acknowledgment Type (ID)<b>Withdrawn</b><br> 
 * MSA-6: Error Condition (CE)<b>Withdrawn</b><br>
 * MSA-7: Message Waiting Number (NM)<b>Optional</b><br> 
 * MSA-8: Message Waiting Priority (ID)<b>Optional</b><br><p>
 * This class provides mechanism to validate message against HL7 v 2.8.2 standard.
 * The class provides accessors & mutators for the elements mentioned above.
 * The class has validate method which validates Message against HL7 v 2.8.2 standard.
 *
 * <p>User can also create Segment through {@link SegmentFactory}
 */
 public class MSA extends Segment   
{
	

	/**
	 * Constructs the MSA segment.
	 */
	public MSA()
	{super(EnumSegments.HL7_SEG_MSA);
	}
	//Integer values used in getter/setter is unique item id defined 
	//for each attribute.

	/**
	 * Retrieves the Acknowledgment Code.
	 * This field contains an acknowledgment code.
	 * @return ID - acknowledgmentCode
	 */
	public ID getAcknowledgmentCode() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(18);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Expected Sequence Number.
	 * This field used in the sequence number protocol.
	 * @return NM - expectedSequenceNumber
	 */
	public NM getExpectedSequenceNumber() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(21);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Message Control ID.
	 * This field contains the message control ID of the message sent by the sending system. 
	 * @return ST - messageControlID
	 */
	public ST getMessageControlID() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(10);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Set the Acknowledgment Code.
	 * This field contains an acknowledgment code.
	 * @param strAcknowledgmentCode This field contains the String Value of  Acknowledgment Code 
	 */ 
	public void setAcknowledgmentCode (String strAcknowledgmentCode) 
	{
		ID acknowledgmentCode  = (ID)getDataElement(18);
		acknowledgmentCode.setValue(strAcknowledgmentCode); 
		setAcknowledgmentCode(acknowledgmentCode);
	} 

	/** Set the Acknowledgment Code.
	 * This field contains an acknowledgment code.
	 * @param objacknowledgmentCode object of  Acknowledgment Code 
	 */ 
	public void setAcknowledgmentCode(ID objacknowledgmentCode)
	{
		setDataType(18,objacknowledgmentCode);
	}

	/**
	 * Set the Expected Sequence Number.
	 * This field used in the sequence number protocol.
	 * @param strExpectedSequenceNumber String which to set as Expected Sequence Number. 
	 */ 
	public void setExpectedSequenceNumber (String strExpectedSequenceNumber) 
	{
		NM expectedSequenceNumber  = (NM)getDataElement(21);
		expectedSequenceNumber.setValue(strExpectedSequenceNumber); 
		setExpectedSequenceNumber(expectedSequenceNumber);
	} 

	/** Set the Expected Sequence Number.
	 * This field used in the sequence number protocol.
	 * @param objexpectedSequenceNumber object of  Expected Sequence Number. 
	 */ 
	public void setExpectedSequenceNumber(NM objexpectedSequenceNumber)
	{
		setDataType(21,objexpectedSequenceNumber);
	}

	/**
	 * Set the Message Control ID.
	 * This field contains the message control ID of the message sent by the sending system. 
	 * @param strMessageControlID String which to set as Message Control ID 
	 */ 
	public void setMessageControlID (String strMessageControlID) 
	{
		ST messageControlID  = (ST)getDataElement(10);
		messageControlID.setValue(strMessageControlID); 
		setMessageControlID(messageControlID);
	} 

	/** Set the Message Control ID.
	 * This field contains the message control ID of the message sent by the sending system. 
	 * @param objmessageControlID object of  Message Control ID 
	 */ 
	public void setMessageControlID(ST objmessageControlID)
	{
		setDataType(10,objmessageControlID);
	}
	
	/**
	 * Retrieves the Message Waiting Number .
	 * If present, indicates the number of messages the Acknowledging  Application has waiting on a queue for the Requesting Application. 
	 * @return NM - MessageWaitingNumber 
	 */
	public NM getMessageWaitingNumber () 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1827 );
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Set the Message Waiting Number .
	 * If present, indicates the number of messages the Acknowledging  Application has waiting on a queue for the Requesting Application. 
	 * @param strMessageWaitingNumber  Specifies Message Waiting Number 
	 */ 
	public void setMessageWaitingNumber  (String strMessageWaitingNumber ) 
	{
		NM MessageWaitingNumber   = (NM)getDataElement(1827 );
		MessageWaitingNumber .setValue(strMessageWaitingNumber ); 
		setMessageWaitingNumber (MessageWaitingNumber );

	} 

	/** Set the Message Waiting Number .
	 * If present, indicates the number of messages the Acknowledging  Application has waiting on a queue for the Requesting Application. 
	 * @param objMessageWaitingNumber  Specifies Message Waiting Number 
	 */ 
	public void setMessageWaitingNumber (NM objMessageWaitingNumber )
	{
		setDataType(1827 ,objMessageWaitingNumber );

	}
	
	/**
	 * Retrieves the  Message Waiting Priority .
	 * If present, indicates that the Sending Application has messages waiting on a queue for the Receiving Application.    
	 * @return ID - MessageWaitingPriority 
	 */
	public ID getMessageWaitingPriority () 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1828 );
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Set the  Message Waiting Priority .
	 * If present, indicates that the Sending Application has messages waiting on a queue for the Receiving Application.  
	 * @param strMessageWaitingPriority  Specifies the the intent of the message    
	 */ 
	public void setMessageWaitingPriority  (String strMessageWaitingPriority )
	{
		ID MessageWaitingPriority   = (ID)getDataElement(1828 );

		MessageWaitingPriority .setValue(strMessageWaitingPriority ); 
		setMessageWaitingPriority (MessageWaitingPriority );

	} 

	/** Set the  Message Waiting Priority .
	 * If present, indicates that the Sending Application has messages waiting on a queue for the Receiving Application.  
	 * @param objMessageWaitingPriority  Specifies the the intent of the message    
	 */ 
	public void setMessageWaitingPriority (ID objMessageWaitingPriority )
	{
		setDataType(1828 ,objMessageWaitingPriority );

	}

	/**
	 * Validates HL7 Message objects .
	 * Validate method checks for validation each and every segments in side the Message object against specified message Structure. 
	 * Validation chcecks 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 or false.
	 * @throws InvalidSegmentException Throws when Segment Validation fails
	 */
	public boolean validate()throws InvalidSegmentException
	{
		try
		{
			super.validate();
			return true;
		}
		catch(FieldMissingException ex)
		{
			throw new InvalidSegmentException(enumSegments.getValue(),ex);
		}
	}
}