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

import java.io.IOException;

import cdac.medinfo.sdk.hl7282.exceptions.InvalidDataTypeException;

/**
 * IDataType interface corresponds to needs to be implemented by all classes which implements functioning of 
 * HL7 Data Type. The methods in this interface can be used  to obtain information about Data Type.  
 * Data types are basic building blocks of segment(fields). HL7 Message consists of segments.
 */
public interface IDataType
{
	/**
	 * Function returns the object of String value in case of primitive DataType.
	 * and ISingleCollection<IDataType> for Composite DataType.
	 * @return  strValue
	 */
	Object getValue();
	
	/**
	 * Reads data from the String.
	 * @param objIHL7Stream - Object of IHL7Stream
	 * @param objIDelimiter - Object of IDelimiter
	 * @return integer - Number of bytes read
	 *				   - Fail if data read is not valid
	 *  @throws IOException Thrown when any IO Operation fails 
	 */
	int read(String strFieldStream,IDelimiter objIDelimiter) throws IOException;
	/**
	 *Writes data to the Stream.
	 *@param objIHL7Stream - Object of IHL7Stream
	 *@param objIDelimiter - Object of IDelimiter
	 *@return the integer value depending on the result
	 * @throws IOException Thrown when any IO Operation fails 
	 */
	int write(IHL7Stream objIHL7Stream,IDelimiter objIDelimiter) throws IOException;
	/**
	 * Validates HL7 DataType objects .
	 * Validate method checks for validation each and every component for composite DataType and String value in side the DataType object against specified HL7 Rules. 
	 * Validation checks include length of Data Type.(Upper bound and Lower bound.
	 * It also checks that given value matches with specifications said by HL7 DataType. 
	 * @return boolean - true or false
	 * @throws InvalidDataTypeException Throws when DataType Validation fails
	 */
	boolean validate();
	
	/**
	 * Sets the value for Data Type as object.
	 * For composite Data Type it will set the MultivaluedPairedCollection 
	 * for primitive Data Type it will set the String.
	 * if it is not as per the expectation then it will not set the value.  
	 */
	public void setValue(Object obj);
	
	/**
	 * Returns the length of Data type. 
	 */
	public int getLength();
	
	/**
	 * Returns the state for Data Type whether it 
	 * is primitive Data Type or composite DataType.
	 * @return true In case of Primitive DataType else false
	 */
	boolean isPrimitive();
	
	/**
	 * Returns the name of Data Type.
	 * @return IDataTypeKey - Name of the Data Type
	 */
	IDataTypeKey getDataTypeName();
}
