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

import java.io.IOException;

import cdac.medinfo.sdk.dcm30_04.commoninterface.IDicomStream;
import cdac.medinfo.sdk.dcm30_04.exceptions.ParseException;
import cdac.medinfo.sdk.dcm30_04.exceptions.SerializeException;
import cdac.medinfo.sdk.dcm30_04.services.dicomnetcommons.EnumElementCoercion;
import cdac.medinfo.sdk.dcm30_04.services.dicomnetcommons.EnumLevelofDigitalSignatureSupport;
import cdac.medinfo.sdk.dcm30_04.services.dicomnetcommons.EnumLevelofSupport;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConstants;
	/**
	 * This Class represents ServiceClassApplicationInformation.
	 */
public class ServiceClassApplicationInformation //ExtendedNegotiationSubitem
{
	EnumLevelofSupport enumLevelofSupport ;
	EnumLevelofDigitalSignatureSupport enumLevelofDigitalSignatureSupport;
	EnumElementCoercion enumElementCoercion;

	public short getLength() 
	{
		return  3 + 3; //3 + 3(reserved).
	}

	/**
	 * Gets Element Coercion
	 * @return the enumElementCoercion
	 */
	public EnumElementCoercion getElementCoercion()
	{
		return enumElementCoercion;
	}

	/**
	 * Sets Element Coercion
	 * @param enumElementCoercion the enumElementCoercion to set
	 */
	public void setElementCoercion(EnumElementCoercion enumElementCoercion) 
	{
		this.enumElementCoercion = enumElementCoercion;
	}

	/**
	 * Gets Level of Digital Signature Support
	 * @return the enumLevelofDigitalSignatureSupport
	 */
	public EnumLevelofDigitalSignatureSupport getLevelofDigitalSignatureSupport() 
	{
		return enumLevelofDigitalSignatureSupport;
	}

	/**
	 * Sets Level of Digital Signature Support.
	 * @param enumLevelofDigitalSignatureSupport the enumLevelofDigitalSignatureSupport to set
	 */
	public void setLevelofDigitalSignatureSupport(EnumLevelofDigitalSignatureSupport enumLevelofDigitalSignatureSupport) 
	{
		this.enumLevelofDigitalSignatureSupport = enumLevelofDigitalSignatureSupport;
	}

	/**
	 * Gets Level of Support
	 * @return the enumLevelofSupport
	 */
	public EnumLevelofSupport getLevelofSupport() 
	{
		return enumLevelofSupport;
	}

	/**
	 * Sets Level of Support
	 * @param enumLevelofSupport the enumLevelofSupport to set
	 */
	public void setLevelofSupport(EnumLevelofSupport enumLevelofSupport) {
		this.enumLevelofSupport = enumLevelofSupport;
	}


	/**
	 * Parses Service Class Application Information Extended Negotiation Subitem.
	 * @param objIDicomStream The stream containing Dicom Data.
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @throws ParseException Signals that Parse exception has occurred.
	 */
	public void parse(IDicomStream objIDicomStream)throws IOException,ParseException
	{
		byte bLevelofSupport,bLevelofDigitalSignatureSupport,bElementCoercion;
		bLevelofSupport = objIDicomStream.readByte();
		objIDicomStream.readByte();
		bLevelofDigitalSignatureSupport = objIDicomStream.readByte();
		objIDicomStream.readByte();
		bElementCoercion = objIDicomStream.readByte();
		objIDicomStream.readByte();

		if(bLevelofSupport == 0)
			enumLevelofSupport = EnumLevelofSupport.LEVEL0;
		else if(bLevelofSupport == 1)
			enumLevelofSupport = EnumLevelofSupport.LEVEL1;
		else if(bLevelofSupport == 2)
			enumLevelofSupport = EnumLevelofSupport.LEVEL2;
		else if(bLevelofSupport == 3)
			enumLevelofSupport = EnumLevelofSupport.LEVEL3;

		if(bLevelofDigitalSignatureSupport == 0)
			enumLevelofDigitalSignatureSupport = EnumLevelofDigitalSignatureSupport.LEVEL0;
		else if(bLevelofDigitalSignatureSupport == 1)
			enumLevelofDigitalSignatureSupport =  EnumLevelofDigitalSignatureSupport.LEVEL1;
		else if(bLevelofDigitalSignatureSupport == 2)
			enumLevelofDigitalSignatureSupport =  EnumLevelofDigitalSignatureSupport.LEVEL2;
		else if(bLevelofDigitalSignatureSupport == 3)
			enumLevelofDigitalSignatureSupport =  EnumLevelofDigitalSignatureSupport.LEVEL3;

		if(bElementCoercion == 0)
			enumElementCoercion = EnumElementCoercion.LEVEL0;
		else if(bElementCoercion == 1)
			enumElementCoercion = EnumElementCoercion.LEVEL1;
		else if(bElementCoercion == 2)
			enumElementCoercion = EnumElementCoercion.LEVEL2;



	}

	/**
	 * This method writes the Service Class Application Information Extended Negotiation Subitem.
	 * @param objIDicomStream  object of the stream onto which the SCU/SCP Role Selection Item is to be written.
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @throws SerializeException Signals that Serialize exception has occurred.
	 */
	public void serialize(IDicomStream objIDicomStream) throws IOException,SerializeException
	{

		objIDicomStream.writeByte(enumLevelofSupport.getValue());
		objIDicomStream.writeByte(DicomConstants.RESERVE_BYTE);
		objIDicomStream.writeByte(enumLevelofDigitalSignatureSupport.getValue());
		objIDicomStream.writeByte(DicomConstants.RESERVE_BYTE);
		objIDicomStream.writeByte(enumElementCoercion.getValue());
		objIDicomStream.writeByte(DicomConstants.RESERVE_BYTE);		
	}



}
