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

import cdac.medinfo.sdk.dcm30_04.services.pdu.RQUserInfoItem;
import cdac.medinfo.sdk.dcm30_04.services.pdu.SOPClassCommonExtNegotItem;
import cdac.medinfo.sdk.dcm30_04.services.pdu.UserInfoItem;

/**
 * This class provides DICOM Application Entity user information.
 * implements getters and setters required in UserInfo for Association RQ.
 */
public class RQUserInfo extends UserInfo 
{

	/** byte value of sub item version. */
	byte bSubItemVersion;

	/** String value of sop class uid. */
	String strSOPClassUID;

	/** String value of service class uid. */
	String strServiceClassUID;

	/**
	 * Retrieves the Sub Item Version.
	 * @return byte - value of Sub Item Version.
	 */
	public byte getSubItemVersion() 
	{
		return bSubItemVersion;
	}

	/**
	 * Sets the Sub Item Version.
	 * @param subItemVersion byte value of SubItemVersion.
	 */
	public void setSubItemVersion(byte subItemVersion) 
	{
		bSubItemVersion = subItemVersion;
	}

	/**
	 * Retrieves the Service Class UID
	 * @return String - value of Service Class UID
	 */
	public String getServiceClassUID() 
	{
		return strServiceClassUID;
	}

	/**
	 * Sets the Service Class UID
	 * @param strSericeClassUID String value of Service Class UID
	 */
	public void setServiceClassUID(String strSericeClassUID) 
	{
		this.strServiceClassUID = strSericeClassUID;
	}

	/**
	 * Retrieves the SOP Class UID.
	 * @return String - value of  SOP Class UID.
	 */
	public String getSOPClassUID() 
	{
		return strSOPClassUID;
	}

	/**
	 * Sets the SOP Class UID.
	 * @param strSOPClassUID String value of SOP Class UID.
	 */
	public void setSOPClassUID(String strSOPClassUID) 
	{
		this.strSOPClassUID = strSOPClassUID;
	}

	/**
	 * Initializes the RQUserInfo according to the given RQUserInfo Item.
	 * @param objRQUserInfoItem instance of RQUserInfoItem
	 */
	public void populate(RQUserInfoItem objRQUserInfoItem)
	{
		super.populate(objRQUserInfoItem);
		if(objRQUserInfoItem != null)
		{
			SOPClassCommonExtNegotItem objSOPClassCommonExtNegotItem = objRQUserInfoItem.getSOPClassCommonExtNegotItem();
			if(objSOPClassCommonExtNegotItem != null)
			{
				this.bSubItemVersion = objSOPClassCommonExtNegotItem.getSubItemVersion();
				this.strSOPClassUID = objSOPClassCommonExtNegotItem.getSOPClassUID();
				this.strServiceClassUID = objSOPClassCommonExtNegotItem.getServiceClassUID();
			}
		}
		//Implementation for RelGenSOPClassID is remaining.
	}

	/**
	 * Initializes the RQUserInfo Item.
	 * @return RQUserInfoItem - instance of RQUserInfoItem
	 */
	public RQUserInfoItem getItem()
	{
		UserInfoItem objUserInfoItem = super.getItem();
		RQUserInfoItem objRQUserInfoItem = new RQUserInfoItem();

		objRQUserInfoItem.setAsyncOpsWindowItem(objUserInfoItem.getAsyncOpsWindowItem());
		objRQUserInfoItem.setImplClassUIDItem(objUserInfoItem.getImplClassUIDItem());
		objRQUserInfoItem.setImplVersionNameItem(objUserInfoItem.getImplVersionNameItem());
		objRQUserInfoItem.setMaxLengthItem(objUserInfoItem.getMaxLengthItem());
		objRQUserInfoItem.setSCUSCPRoleSelectionItem(objUserInfoItem.getSCUSCPRoleSelectionItem());		
		objRQUserInfoItem.setSOPClassExtNegotiationItems(objUserInfoItem.getSOPClassExtNegotiationItems());

		SOPClassCommonExtNegotItem objSOPClassCommonExtNegotItem = new SOPClassCommonExtNegotItem();
		objSOPClassCommonExtNegotItem.setSubItemVersion(this.getSubItemVersion());

		String strSOPClassUID = this.getSOPClassUID();
		objSOPClassCommonExtNegotItem.setSOPClassUID(strSOPClassUID);
//		if(strSOPClassUID != null)
//			objSOPClassCommonExtNegotItem.setSOPClassUIDLentgh((short)strSOPClassUID.length());

		String strServiceUID = this.getServiceClassUID();
		objSOPClassCommonExtNegotItem.setServiceClassUID(strServiceUID);
//		if(strServiceUID != null)
//			objSOPClassCommonExtNegotItem.setServiceClassUIDLength((short)strServiceUID.length());
		//Implementation for RelGenSOPClassID is remaining.
		return objRQUserInfoItem;
	}
	
	/**
	 * Validates the RQUserInfo for mandatory attributes
	 * @return boolean - shows status as true or false
	 */
	public boolean validate()
	{
		if(!super.validate())
			return false;
		
		return true;
	}
}
