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

import cdac.medinfo.sdk.hl7282.utils.IAttributeItem;

/**
 * AttributeItem class is the implementation of IAttributeItem.
 * AttributeItem represents structure of a attribute of a segment as defined in HL7 standard.
 */
public final class AttributeItem implements IAttributeItem 
{
	
	private String strFieldName;
	private int iItemID;
	private int iSequenceNo;
	private int iMinLength;
	private int iMaxLength;
	private String strCLength;
	private String strDataType;
	private int[] iTableNo = null;
	private boolean bRepeatable;
	private int intOccurrence;
	private boolean bOptional;

	/**
	 * Default Constructor for AttributeItem.
	 */
	public AttributeItem()
	{}

	/**
	 * Parameterized constructor for Attribute which initializes different fields of an item.
	 * @param strFieldName Name of Field name
	 * @param intItemID Integer value of an Item ID
	 * @param intSeq Integer value of Sequence number of an Item ID
	 * @param minLen Integer value of Minimum Length of an Item ID
	 * @param maxLen Integer value of Maximum Length of an Item ID
	 * @param cLen Integer value of Conformance Length of an Item ID
	 * @param strDataType Integer value of Data type of an Item ID
	 * @param intTableNo Integer value of  Table number of an Item ID
	 * @param bRepeatable Show status of an Item whether repeatable or not
	 * @param bOptional Show status of an Item whether optional or not
	 */
	public AttributeItem(String strFieldName, int intItemID, int intSeq, int minLen ,int maxLen ,String cLen, String strDataType, int[] intTableNo, boolean bRepeatable,  boolean bOptional)
	{
		this.strFieldName = strFieldName;
		this.iItemID = intItemID;
		this.iSequenceNo = intSeq;
		this.iMinLength = minLen;
		this.iMaxLength = maxLen;
		this.strCLength = cLen;
		this.strDataType = strDataType;
		this.iTableNo = intTableNo;
		this.bRepeatable = bRepeatable;
		this.intOccurrence = 1;
		this.bOptional = bOptional;
	}
	
	/**
	 * Parameterized constructor for Attribute which initializes different fields of an item.
	 * @param strFieldName Name of Field name
	 * @param intItemID Integer value of an Item ID
	 * @param intSeq Integer value of Sequence number of an Item ID
	 * @param minLen Integer value of Minimum Length of an Item ID
	 * @param maxLen Integer value of Maximum Length of an Item ID
	 * @param cLen Integer value of Conformance Length of an Item ID
	 * @param strDataType Integer value of Data type of an Item ID
	 */
	public AttributeItem(String strFieldName, int intItemID, int intSeq,  int minLen ,int maxLen ,String cLen, String strDataType)
	{
		this.strFieldName = strFieldName;
		this.iItemID = intItemID;
		this.iSequenceNo = intSeq;
		this.iMinLength = minLen;
		this.iMaxLength = maxLen;
		this.strCLength = cLen;
		this.strDataType = strDataType;
	}

	/**
	 * Retrieves name of attribute.
	 * @return String - name of attribute
	 */
	public String getFieldName()
	{
		return strFieldName;
	}

	/**
	 * Sets name of attribute.
	 * @param strName name of attribute
	 */
	public void setFieldName(String strName) 
	{
		this.strFieldName = strName;
	}

	/**
	 * Retrieves Item ID for attribute defined by HL7 standard.
	 * @return int value of ItemID
	 */
	public int getItemID()
	{
		return iItemID;
	}

	/**
	 * Sets Item ID for attribute defined by HL7 standard.
	 * @param intItemID value of ItemID
	 */
	public void setItemID(int intItemID)
	{
		this.iItemID = intItemID;
	}

	/**
	 * Retrieves sequence number for attribute defined by HL7 standard in segment.
	 * @return int - value of sequence index
	 */
	public int getSequenceNo()
	{
		return iSequenceNo;
	}

	/**
	 * Sets sequence number for attribute defined by HL7 standard in segment.
	 * @param intSeq value of sequence index
	 */
	public void setSequenceNo(int intSeq)
	{
		this.iSequenceNo = intSeq;
	}

	/**
	 * Retrieves Maximum Length for attribute defined by HL7 standard in segment.
	 * @return int - value of Maximum length
	 */
	public int getMaximumLength()
	{
		return iMaxLength;
	}

	/**
	 * Sets Maximum Length for attribute defined by HL7 standard in segment.
	 * @param maxLen Maximum length value
	 */
	public void setMaximumLength(int maxLen)
	{
		this.iMaxLength = maxLen;
	}
	
	/**
	 * Retrieves Minimum Length for attribute defined by HL7 standard in segment.
	 * @return int - value of Minimum length
	 */
	public int getMinimumLength()
	{
		return iMinLength;
	}
	
	/**
	 * Sets Minimum Length for attribute defined by HL7 standard in segment.
	 * @param minLen Minimum length value
	 */
	public void setMinimumLength(int minLen)
	{
		this.iMinLength = minLen;
	}
	
	/**
	 * Retrieves Conformance Length for attribute defined by HL7 standard in segment.
	 * @return String - value of Conformance length
	 */
	public String getConformanceLength()
	{
		return strCLength;
	}
	
	/**
	 * Sets Conformance Length for attribute defined by HL7 standard in segment.
	 * @param cLen Conformance length value
	 */
	public void setConformanceLength(String cLen)
	{
		this.strCLength = cLen;
	}
	

	/**
	 * Retrieves Data Type for attribute defined by HL7 standard in segment.
	 * @return String name of DataType
	 */
	public String getDataType()
	{
		return strDataType;
	}

	/**
	 * Sets Datatype for attribute defined by HL7 standard in segment.
	 * @param strDataType name of attribute
	 */
	public void setDataType(String strDataType)
	{
		this.strDataType = strDataType;
	}

	/**
	 * Retrieves Table number for attribute defined by HL7 standard in segment.
	 * @return int[] - array of table number
	 */
	public int[] getTableNo() 
	{
		return iTableNo;
	}

	/**
	 * Sets Table number for attribute defined by HL7 standard in segment.
	 * @param intTableNo array of table number
	 */
	public void setTableNo(int[] intTableNo)
	{
		this.iTableNo = intTableNo;
	}

	/**
	 * Shows repeatability status for attribute defined by HL7 standard in segment.
	 * @return boolean - status as true or false
	 */
	public boolean isRepeatable() 
	{
		return bRepeatable;
	}

	/**
	 * Sets repeatability status for attribute defined by HL7 standard in segment.
	 * @param bRepeatable status as true or false
	 */
	public void setRepeatable(boolean bRepeatable)
	{
		this.bRepeatable = bRepeatable;
	}
	
	/**
	 * Retrieves Occurrence for attribute defined by HL7 standard in segment.
	 * @return int - Number of Occurrence of the attribute
	 */
	public int getOccurrence()
	{
		if(bRepeatable)
		{
			if(intOccurrence > 1)
			{
				return intOccurrence;
			}
			else
				return -1;
		}
		else
		{
			return 1;
		}
	}
	
	/**
	 * Sets Occurrence for attribute defined by HL7 standard in segment.
	 * @param intOccurrence Size of the attribute
	 */
	public void setOccurrence(int intOccurrence)
	{
		this.intOccurrence = intOccurrence;
	}

	/**
	 * Shows optionality status for attribute defined by HL7 standard in segment.
	 * @return boolean - status as true or false
	 */
	public boolean isOptional()
	{
		return this.bOptional;
	}

	/**
	 * Sets optionality status for attribute defined by HL7 standard in segment.
	 * @param bOptional status as true or false
	 */
	public void setOptional(boolean bOptional)
	{
		this.bOptional = bOptional;
	}
}
