/*******************************************************************************
 *  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.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.InvalidSegmentException;
import cdac.medinfo.sdk.hl7282.utils.EnumSegments;
import cdac.medinfo.sdk.hl7282.utils.SingleCollection;

/**
 * BTS - Batch trailer segment  <p>
 * The BTS segment defines the end of a batch.
 * <p>Represents an HL7 BTS message segment. 
 * This segment has the following fields:</p><p>
 * BTS-1: Batch Message Count (ST)<b>Optional</b><br> 
 * BTS-2: Batch Comment (ST)<b>Optional</b><br> 
 * BTS-3: Batch Totals (NM)<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 BTS extends Segment    
{
	

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

	/**
	 * Set the Batch Message Count
	 * This field contains the count of the individual messages contained within the batch
	 * @param strBatchMessageCount - String value of BatchMessageCount
	 */ 
	public void setBatchMessageCount(String strBatchMessageCount)
	{
		ST batchMessageCount  = (ST)getDataElement(93);
		batchMessageCount.setValue(strBatchMessageCount); 
		setBatchMessageCount(batchMessageCount);
	} 

	/** Set the Batch Message Count
	 * This field contains the count of the individual messages contained within the batch
	 * @param objbatchMessageCount object of BatchMessageCount
	 */ 
	public void setBatchMessageCount(ST objbatchMessageCount)
	{
		setDataType(93,objbatchMessageCount);
	}
	/**
	 * Retrieves the Batch Message Count.
	 * @return String - BatchMessageCount
	 */
	public ST getBatchMessageCount() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(93);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Set the Batch Comment.
	 * This field is a comment field that is not further defined in the HL7 protocol.
	 * @param strBatchComment - String value of Batch Comment
	 */ 
	public void setBatchComment(String strBatchComment)
	{
		ST batchComment  = (ST)getDataElement(90);
		batchComment.setValue(strBatchComment); 
		setBatchComment(batchComment);
	} 

	/** Set the Batch Comment.
	 * This field is a comment field that is not further defined in the HL7 protocol.
	 * @param objbatchComment object of Batch Comment
	 */ 
	public void setBatchComment(ST objbatchComment)
	{
		setDataType(90,objbatchComment);
	}
	/**
	 * Retrieves the Batch Comment.
	 * @return String - BatchComment
	 */
	public ST getBatchComment() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(90);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Set the Batch Totals.
	 * This field contains the batch total
	 * @param strBatchTotals Batch Totals.
	 */ 
	public void addBatchTotals(String strBatchTotals)
	{
		NM tempBatchTotals  = (NM)getDataElement(95);
		tempBatchTotals.setValue(strBatchTotals); 
		addBatchTotals(tempBatchTotals);
	} 

	/** Set the Batch Totals.
	 * This field contains the batch total
	 * @param objtempBatchTotals object of Batch Totals.
	 */ 
	public void addBatchTotals(NM objtempBatchTotals)
	{
		addDataType(95,objtempBatchTotals);
	}
	/**
	 * Set the Batch Totals.
	 * This field contains the batch total.
	 * @param objBatchTotalsList List of batch total.
	 */	
	@SuppressWarnings("unchecked")
	public void setBatchTotals(ISingleCollection<NM> objBatchTotalsList)
	{
		ISingleCollection<IDataType> objCollection = null;
		ISingleCollection<?> objUnknownCollection = (ISingleCollection<?>)objBatchTotalsList;
		objCollection = (ISingleCollection<IDataType>)objUnknownCollection;
		setDataType(95,objCollection);
	}
	/**
	 * Retrieves Batch Totals. 
	 * @return ISingleCollection<NM> - rangeofDecimalPrecision
	 */
	public ISingleCollection<NM> getBatchTotals() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(95);
		ISingleCollection<NM> objDataList = new SingleCollection<NM>(); 
		if(objDataCollection != null && objDataCollection.size() != 0)
		{
			for(IDataType objDataType : objDataCollection)
			{
				NM objNM = (NM)objDataType;
				objDataList.add(objNM);
			}
		}
		return objDataList;
	}

	/** 
	 * 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 Thrown when Segment Validation Fails.
	 */
	@Override
	public boolean validate() throws InvalidSegmentException
	{
		//All fields are optional
		super.validate();
		return true;
	}

}
