/*******************************************************************************
 *  Copyright 2017-2018 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.dcm30_04.baselibs;

import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataElement;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDictionaryReader;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITransferSyntax;
import cdac.medinfo.sdk.dcm30_04.enums.EnumBold;
import cdac.medinfo.sdk.dcm30_04.enums.EnumFontNameType;
import cdac.medinfo.sdk.dcm30_04.enums.EnumHorizontalAlignment;
import cdac.medinfo.sdk.dcm30_04.enums.EnumItalic;
import cdac.medinfo.sdk.dcm30_04.enums.EnumShadowStyle;
import cdac.medinfo.sdk.dcm30_04.enums.EnumUnderlined;
import cdac.medinfo.sdk.dcm30_04.enums.EnumVerticalAlignment;
import cdac.medinfo.sdk.dcm30_04.exceptions.ConditionFailedException;
import cdac.medinfo.sdk.dcm30_04.exceptions.InvalidItemException;
import cdac.medinfo.sdk.dcm30_04.exceptions.MandatoryMissingException;
import cdac.medinfo.sdk.dcm30_04.exceptions.ValidationException;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConfig;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConstants;
import cdac.medinfo.sdk.dcm30_04.utils.DicomLogger;

/**
* This item class contains methods to validate, set and get the attributes of Text Style Sequence.
 */
public class TextStyleSequenceItem extends Item   
{
	

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * This constructor creates the item and internal code sequence macro with default TransferSyntax 
	 */
	TextStyleSequenceItem()
	{
		super();
	}


	/**
	 * This constructor creates the item and internal code sequence macro with specified TransferSyntax 
	 * and default DictionaryReader
	 * @param objITransferSyntax specifies the DICOM Standard defined TransfeSyntax
	 */
	TextStyleSequenceItem(ITransferSyntax objITransferSyntax)
	{
		super(objITransferSyntax);
	}

	/**
	 * This constructor creates TextStyleSequenceItem with specified TransferSyntax and
	 * specified DictionaryReader
	 * @param objTransferSyntax specifies the DICOM Standard defined TransfeSyntax
	 * @param objDictionaryReader specifies the DICOM Dictionary reader to be used 
	 */
	TextStyleSequenceItem(ITransferSyntax objTransferSyntax, IDictionaryReader objDictionaryReader)
	{
		super(objTransferSyntax,objDictionaryReader);
	}



	/**
	 * Validates all the attributes in TextStyleSequenceItem that are present in the DataSet
	 * @return boolean - Success -true, Failure - false
	 * @throws InvalidItemException throws InvalidItemException If Conditional element fails.
	 */
	public boolean validateForModule()  throws InvalidItemException
	{
		try
		{
			if(contains(0x0070,0x0227))
				if(!contains(0x0070,0x0228))
					throw new ConditionFailedException("0x0070,0x0228") ;
			if(!contains(0x0070,0x0229))
				throw new MandatoryMissingException("0070,0229") ;
			if(!contains(0x0070,0x0241))
				throw new MandatoryMissingException("0070,0241") ;
			if(!contains(0x0070,0x0244))
				throw new MandatoryMissingException("0070,0244") ;
			if(!contains(0x0070,0x0245))
				throw new MandatoryMissingException("0070,0245") ;
			if(!contains(0x0070,0x0246))
				throw new MandatoryMissingException("0070,0246") ;
			if(!contains(0x0070,0x0247))
				throw new MandatoryMissingException("0070,0247") ;
			if(!contains(0x0070,0x0258))
				throw new MandatoryMissingException("0070,0258") ;
			if(!contains(0x0070,0x0248))
				throw new MandatoryMissingException("0070,0248") ;
			if(!contains(0x0070,0x0249))
				throw new MandatoryMissingException("0070,0249") ;
			if(!contains(0x0070,0x0250))
				throw new MandatoryMissingException("0070,0250") ;
		}
		catch( MandatoryMissingException ce)
		{
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger.getLogger().log(ce.getMessage());
			}
			throw new InvalidItemException(this.getClass().getSimpleName(),ce); 
		}
		catch(ConditionFailedException ce)
		{
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger.getLogger().log(ce.getMessage());
			}
			throw new ValidationException(this.getClass().getSimpleName(),ce); 
		}
		return true;
	}
	
	/**
	 * Sets Font Name.
	 * Font name in a standard type.
	 * @param strFontName String value of Font Name.
	 */
	public void setFontName(String strFontName)
	{
		/* Accept the Font Name in String format of type LO.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0070,0x0227, strFontName,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0227,DicomConstants.DCM_DT_LO, strFontName);

		addDataElement(objIDataElement);
	}

	/**
	 * Return Font Name.
	 * Font name in a standard type.
	 * @return String - value of Font Name.
	 */
	public String getFontName()
	{
		Object objValue = getValue(0x0070,0x0227);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Font Name Type
	 * Defined Terms:
	 * 1) ISO_32000.
	 * @param enumFontNameType enum value of Font Name Type.
	 */
	public void setFontNameType(EnumFontNameType enumFontNameType)
	{
		/* Accept the Font Name Type in String format of type CS.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0070,0x0228, enumFontNameType.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0228,DicomConstants.DCM_DT_CS, enumFontNameType.getValue());

		addDataElement(objIDataElement);


	}

	/**
	 * Return type of Font Name. 
	 * @return String - value of Font Name Type.
	 */
	public String getFontNameType()
	{
		Object objValue = getValue(0x0070,0x0228);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets CSS Font Name.
	 * Generic font name as defined within CSS (Cascading Style Sheets).
	 * @param strCSSFontName String value of CSS Font Name.
	 */
	public void setCSSFontName(String strCSSFontName)
	{
		/* Accept the CSS Font Name in String format of type LO.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0070,0x0229, strCSSFontName,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0229,DicomConstants.DCM_DT_LO, strCSSFontName);

		addDataElement(objIDataElement);
	}

	/**
	 * Return CSS Font Name.
	 * Generic font name as defined within CSS (Cascading Style Sheets).
	 * @return String - value of CSS Font Name.
	 */
	public String getCSSFontName()
	{
		Object objValue = getValue(0x0070,0x0229);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Text Color CIELab Value.
	 * A default color triplet value used to specify the text color in which 
	 * it is recommended that the text be rendered on a color display.
	 * @param shTextColorCIELabValue short value of Number of significant bits
	 */
	public void setTextColorCIELabValue(short shTextColorCIELabValue)
	{
		/* Accept the Text Color CIELab Value of type US.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0070,0x0241,shTextColorCIELabValue,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0241,DicomConstants.DCM_DT_US, shTextColorCIELabValue);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Text Color CIELab Value.
	 * A default color triplet value used to specify the text color in which 
	 * it is recommended that the text be rendered on a color display.
	 * @return short - short value of Text Color CIELab Value
	 */
	public short getTextColorCIELabValue()
	{
		Object objValue = getValue(0x0070,0x0241);
		if(objValue != null)
			return Short.parseShort(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets Horizontal Alignment.
	 * Specifies the horizontal position of the text relative to the vertical edges of the bounding box.
	 * Defined Terms:
	 * 1) LEFT.
	 * 2) CENTER.
	 * 3) RIGHT.
	 * @param enumHorizontalAlignment enum value of Horizontal Alignment.
	 */
	public void setHorizontalAlignment(EnumHorizontalAlignment enumHorizontalAlignment)
	{
		/* Accept the Horizontal Alignment in String format of type CS.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0070,0x0242, enumHorizontalAlignment.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0242,DicomConstants.DCM_DT_CS, enumHorizontalAlignment.getValue());

		addDataElement(objIDataElement);


	}

	/**
	 * Return Horizontal Alignment.
	 * Specifies the horizontal position of the text relative to the vertical edges of the bounding box.  
	 * @return String - value of Horizontal Alignment.
	 */
	public String getHorizontalAlignment()
	{
		Object objValue = getValue(0x0070,0x0242);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Vertical Alignment.
	 * Specifies the vertical position of the text relative to the horizontal edges of the bounding box.
	 * Defined Terms:
	 * 1) TOP.
	 * 2) CENTER.
	 * 3) BOTTOM.
	 * @param enumVerticalAlignment enum value of Vertical Alignment.
	 */
	public void setVerticalAlignment(EnumVerticalAlignment enumVerticalAlignment)
	{
		/* Accept the Vertical Alignment in String format of type CS.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0070,0x0243, enumVerticalAlignment.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0243,DicomConstants.DCM_DT_CS, enumVerticalAlignment.getValue());

		addDataElement(objIDataElement);


	}

	/**
	 * Return Vertical Alignment.
	 * Specifies the vertical position of the text relative to the horizontal edges of the bounding box.
	 * @return String - value of Vertical Alignment.
	 */
	public String getVerticalAlignment()
	{
		Object objValue = getValue(0x0070,0x0243);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Shadow Style.
	 * The shadow style of the text to be displayed.
	 * Defined Terms:
	 * 1) NORMAL.
	 * 2) OUTLINED.
	 * 3) OFF.
	 * @param enumShadowStyle enum value of Shadow Style.
	 */
	public void setShadowStyle(EnumShadowStyle enumShadowStyle)
	{
		/* Accept the Shadow Style in String format of type CS.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0070,0x0244, enumShadowStyle.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0244,DicomConstants.DCM_DT_CS, enumShadowStyle.getValue());

		addDataElement(objIDataElement);


	}

	/**
	 * Return Shadow Style.
	 * The shadow style of the text to be displayed.
	 * @return String - value of Shadow Style.
	 */
	public String getShadowStyle()
	{
		Object objValue = getValue(0x0070,0x0244);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Shadow Offset X.
	 * @param fShadowOffsetX Float value of the Shadow Offset X.
	 */
	public void setShadowOffsetX( float fShadowOffsetX)
	{
		/*
		 * Accept the Shadow Offset X in String format of type FL.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0070,0x0245, fShadowOffsetX,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0245,DicomConstants.DCM_DT_FL, fShadowOffsetX);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the Shadow Offset X.
	 * @return float - Float value of the Shadow Offset X.
	 */
	public float getShadowOffsetX()
	{
		Object objValue = getValue(0x0070,0x0245);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets Shadow Offset Y.
	 * @param fShadowOffsetY Float value of the Shadow Offset Y.
	 */
	public void setShadowOffsetY( float fShadowOffsetY)
	{
		/*
		 * Accept the Shadow Offset Y in String format of type FL.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0070,0x0246, fShadowOffsetY,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0246,DicomConstants.DCM_DT_FL, fShadowOffsetY);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the Shadow Offset Y.
	 * @return float - Float value of the Shadow Offset Y.
	 */
	public float getShadowOffsetY()
	{
		Object objValue = getValue(0x0070,0x0246);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets Shadow Color CIELab Value.
	 * A color triplet value used to encode the Shadow Color.
	 * @param shShadowColorCIELabValue short value of Shadow Color CIELab Value
	 */
	public void setShadowColorCIELabValue(short shShadowColorCIELabValue)
	{
		/* Accept the Shadow Color CIELab Value of type US.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0070,0x0247,shShadowColorCIELabValue,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0247,DicomConstants.DCM_DT_US, shShadowColorCIELabValue);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Shadow Color CIELab Value.
	 * A color triplet value used to encode the Shadow Color.
	 * @return short - short value of Shadow Color CIELab Value
	 */
	public short getShadowColorCIELabValue()
	{
		Object objValue = getValue(0x0070,0x0247);
		if(objValue != null)
			return Short.parseShort(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets the Shadow Opacity.
	 * Encodes the shadow opacity.
	 * @param fShadowOpacity Float value of the Shadow Opacity
	 */
	public void setShadowOpacity( float fShadowOpacity)
	{
		/*
		 * Accept the Shadow Opacity in String format of type FL.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0070,0x0258, fShadowOpacity,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0258,DicomConstants.DCM_DT_FL, fShadowOpacity);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the Shadow Opacity.
	 * Encodes the shadow opacity.
	 * @return float - Float value of the Shadow Opacity.
	 */
	public float getShadowOpacity()
	{
		Object objValue = getValue(0x0070,0x0258);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets Underlined.
	 * Specifies whether or not the text shall be rendered underlined.
	 * Defined Terms:
	 * 1) Y.
	 * 2) N.
	 * @param enumUnderlined enum value of Underlined.
	 */
	public void setUnderlined(EnumUnderlined enumUnderlined)
	{
		/* Accept the Underlined in String format of type CS.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0070,0x0248, enumUnderlined.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0248,DicomConstants.DCM_DT_CS, enumUnderlined.getValue());

		addDataElement(objIDataElement);


	}

	/**
	 * Return Underlined. 
	 * Specifies whether or not the text shall be rendered underlined.
	 * @return String - value of Underlined.
	 */
	public String getUnderlined()
	{
		Object objValue = getValue(0x0070,0x0248);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Bold.
	 * Specifies whether or not the text shall be rendered in bold.
	 * Defined Terms:
	 * 1) Y.
	 * 2) N.
	 * @param enumBold enum value of Bold.
	 */
	public void setBold(EnumBold enumBold)
	{
		/* Accept the Bold in String format of type CS.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0070,0x0249, enumBold.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0249,DicomConstants.DCM_DT_CS, enumBold.getValue());

		addDataElement(objIDataElement);


	}

	/**
	 * Return Bold.
	 * Specifies whether or not the text shall be rendered in bold.
	 * @return String - value of Bold.
	 */
	public String getBold()
	{
		Object objValue = getValue(0x0070,0x0249);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Italic.
	 * Specifies whether or not the text shall be rendered italicized.
	 * Defined Terms:
	 * 1) Y.
	 * 2) N.
	 * @param enumItalic enum value of Italic.
	 */
	public void setItalic(EnumItalic enumItalic)
	{
		/* Accept the Italic in String format of type CS.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0070,0x0250, enumItalic.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0250,DicomConstants.DCM_DT_CS, enumItalic.getValue());

		addDataElement(objIDataElement);


	}

	/**
	 * Return Italic.
	 * Specifies whether or not the text shall be rendered italicized.
	 * @return String - value of Italic.
	 */
	public String getItalic()
	{
		Object objValue = getValue(0x0070,0x0250);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

}
