/*******************************************************************************
 *  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.EnumLineDashingStyle;
import cdac.medinfo.sdk.dcm30_04.enums.EnumShadowStyle;
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 the methods to set, get and validate the attribute present in Line Style Sequence .
 */

public class LineStyleSequenceItem extends Item   
{
	

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * This constructor creates the item and internal code sequence macro with default TransferSyntax 
	 */
	LineStyleSequenceItem()
	{
		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
	 */
	LineStyleSequenceItem(ITransferSyntax objITransferSyntax)
	{
		super(objITransferSyntax);
	}

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



	/**
	 * Validates all the attributes in LineStyleSequenceItem 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,0x0254) && getDataForTag(0x0070, 0x0254).getValue().equals(EnumLineDashingStyle.DASHED))
				if(!contains(0x0070,0x0255))
					throw new ConditionFailedException("0x0070,0x0255") ;
			
			if(!contains(0x0070,0x0251))
				throw new MandatoryMissingException("0070,0251") ;
			if(!contains(0x0070,0x0284))
				throw new MandatoryMissingException("0070,0284") ;
			if(!contains(0x0070,0x0253))
				throw new MandatoryMissingException("0070,0253") ;
			if(!contains(0x0070,0x0254))
				throw new MandatoryMissingException("0070,0254") ;
			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") ;
		}
		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 Pattern On Color CIELab Value.
	 * A color triplet value used to encode the foreground.
	 * @param shPatternOnColorCIELabValue short value of Pattern On Color CIELab
	 */
	public void setPatternOnColorCIELabValue(short shPatternOnColorCIELabValue)
	{
		/* Accept the Pattern On 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,0x0251,shPatternOnColorCIELabValue,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0251,DicomConstants.DCM_DT_US, shPatternOnColorCIELabValue);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Pattern On Color CIELab Value.
	 * A color triplet value used to encode the foreground.
	 * @return short - short value of Pattern On Color CIELab
	 */
	public short getPatternOnColorCIELabValue()
	{
		Object objValue = getValue(0x0070,0x0251);
		if(objValue != null)
			return Short.parseShort(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets Pattern Off Color CIELab Value.
	 * A color triplet value used to encode the color of parts of the line that are off, i.e., the background.
	 * @param shPatternOffColorCIELabValue short value of Pattern Off Color CIELab
	 */
	public void setPatternOffColorCIELabValue(short shPatternOffColorCIELabValue)
	{
		/* Accept the Pattern Off 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,0x0252,shPatternOffColorCIELabValue,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0252,DicomConstants.DCM_DT_US, shPatternOffColorCIELabValue);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Pattern Off Color CIELab Value.
	 * A color triplet value used to encode the color of parts of the line that are off, i.e., the background.
	 * @return short - short value of Pattern Off Color CIELab
	 */
	public short getPatternOffColorCIELabValue()
	{
		Object objValue = getValue(0x0070,0x0252);
		if(objValue != null)
			return Short.parseShort(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets the Pattern On Opacity.
	 * Encodes the foreground opacity.
	 * @param fPatternOnOpacity Float value of the Pattern On Opacity
	 */
	public void setPatternOnOpacity( float fPatternOnOpacity)
	{
		/*
		 * Accept the Pattern On 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,0x0284, fPatternOnOpacity,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0284,DicomConstants.DCM_DT_FL, fPatternOnOpacity);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the Pattern On Opacity.
	 * Encodes the foreground opacity.
	 * @return float - Float value of the Pattern On Opacity
	 */
	public float getPatternOnOpacity()
	{
		Object objValue = getValue(0x0070,0x0284);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets the Pattern Off Opacity.
	 * Encodes the background opacity.
	 * @param fPatternOffOpacity Float value of the Pattern Off Opacity
	 */
	public void setPatternOffOpacity( float fPatternOffOpacity)
	{
		/*
		 * Accept the Pattern Off 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,0x0285, fPatternOffOpacity,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0285,DicomConstants.DCM_DT_FL, fPatternOffOpacity);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the Pattern Off Opacity.
	 * Encodes the background opacity.
	 * @return float - Float value of the Pattern Off Opacity
	 */
	public float getPatternOffOpacity()
	{
		Object objValue = getValue(0x0070,0x0285);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets the Line Thickness.
	 * Specifies the line thickness.
	 * @param fLineThickness Float value of the Line Thickness
	 */
	public void setLineThickness( float fLineThickness)
	{
		/*
		 * Accept the Line Thickness 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,0x0253, fLineThickness,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0253,DicomConstants.DCM_DT_FL, fLineThickness);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the Line Thickness.
	 * Specifies the line thickness.
	 * @return float - Float value of the Line Thickness
	 */
	public float getLineThickness()
	{
		Object objValue = getValue(0x0070,0x0253);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets Line Dashing Style.
	 * The dashing style of the line to be displayed.
	 * Defined Terms:
	 * 1) SOLID.
	 * 2) DASHED.
	 * @param enumSetupDeviceType enum value of Line Dashing Style.
	 */
	public void setLineDashingStyle(EnumLineDashingStyle enumSetupDeviceType)
	{
		/* Accept the Line Dashing 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,0x0254, enumSetupDeviceType.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0070,0x0254,DicomConstants.DCM_DT_CS, enumSetupDeviceType.getValue());

		addDataElement(objIDataElement);


	}

	/**
	 * Return Line Dashing Style. 
	 * The dashing style of the line to be displayed.
	 * @return String - value of Line Dashing Style.
	 */
	public String getLineDashingStyle()
	{
		Object objValue = getValue(0x0070,0x0254);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Line Pattern.
	 * Pattern that defines the line dashing style.
	 * @param iLinePattern long value of Line Pattern.
	 */
	public void setLinePattern(int iLinePattern)
	{
		/* Accept the Line Pattern of type UL.
		 * 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,0x0255, iLinePattern,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0070,0x0255,DicomConstants.DCM_DT_UL, iLinePattern);
		//Add the DataElement to the Item
		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Line Pattern.
	 * Pattern that defines the line dashing style.
	 * @return long - value of Dimension Organization UID.
	 */
	public int getLinePattern()
	{
		Object objValue = getValue(0x0070,0x0255);
		if(objValue != null)
			return Integer.parseInt(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * 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.
	 * Floating point value that defines the shadow offset in X direction 
	 * in Graphic Annotation Units (0070,0005).
	 * @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.
	 * Floating point value that defines the shadow offset in X direction 
	 * in Graphic Annotation Units (0070,0005).
	 * @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.
	 * Floating point value that defines the shadow offset in Y direction 
	 * in Graphic Annotation Units (0070,0005).
	 * @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.
	 * Floating point value that defines the shadow offset in Y direction 
	 * in Graphic Annotation Units (0070,0005).
	 * @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;
	}

}
