//------------------------------------------------------------------------------
// <copyright file="SessionStartInfo.java" company="Microsoft">
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
// <summary>
//      SessionStart Info class
// </summary>
//------------------------------------------------------------------------------


package com.microsoft.hpc.scheduler.session;

import java.util.ArrayList;
import java.util.List;

import org.datacontract.schemas._2004._07.microsoft_hpc_scheduler.JobPriority;
import org.datacontract.schemas._2004._07.microsoft_hpc_scheduler.JobUnitType;

/**
 * This class includes the parameters for modifying <code>SessionStartInfo</code> for a session.
 * 
 * <p>Subclass of <code>com.microsoft.hpc.SessionStartInfo</code> designed to be a simplified version that
 * does not use ObjectFactories for the JAXBElements needed for Java SOA.</p>
 * 
 * the use of this class is required as it contains the
 * headnode variable, while the <code>SessionStartInfo</code> in <code>com.microsoft.hpc.SessionStartInfo</code>
 * does not and should not be used (ie. <code>import com.microsoft.hpc.SessionStartInfo;</code> should <b><i>NEVER</i></b>
 *  be called explicitly).</p>  
 * 
 * @see com.microsoft.hpc.SessionStartInfo
 * @see com.microsoft.hpc.ObjectFactory
 * @see JAXBElement
 */
public class SessionStartInfo extends com.microsoft.hpc.SessionStartInfoContract
{   
    private static com.microsoft.hpc.ObjectFactory factory = new com.microsoft.hpc.ObjectFactory();
    
    private String headnode; 
    
    /**
     * Initializes an instance of the SessionStartInfo class with a parameter for headnode, service, username, and password.
     * 
     * <p>SessionStartInfo is initialized with the following default values:</p>
     * <p>TransportScheme = [Http];</p>
     * <p>Runtime = 3600; (seconds, == 1 hr)</p>
     * <p>ShareSession = false;</p>
     * 
     * @param headnode  headnode you wish to connect to
     * @param service   service name you wish to use
     * @param username  username
     * @param password  password
     */
    public SessionStartInfo(String headnode, String service, String username, String password)
    {
        super();
        
        this.setHeadnode(headnode);
                
        this.setServiceName(factory.createSessionStartInfoContractServiceName(service));
        
        this.getTransportScheme().add("Http");
        
        this.setUsername(factory.createSessionStartInfoContractUsername(username));
        this.setPassword(factory.createSessionStartInfoContractPassword(password));
        
        this.setRuntime(3600);

        this.setShareSession(false);
    }
    
    /**
     * Initializes an instance of the SessionStartInfo class with a parameter for headnode, service
     * 
     * <p>SessionStartInfo is initialized with the following default values:</p>
     * <p>TransportScheme = [Http];</p>
     * <p>Runtime = 3600; (seconds, == 1 hr)</p>
     * <p>ShareSession = false;</p>
     * <p>Username = HpcJava.user</p>
     * <p>Password = HpcJava.pass</p>
     * 
     * @param headnode  headnode you wish to connect to
     * @param service   service name you wish to use
     * @see HpcJava#setUsernamePassword(String, String)
     */
    public SessionStartInfo(String headnode, String service)
    {
        super();

        this.setHeadnode(headnode);
            
        this.setServiceName(factory.createSessionStartInfoContractServiceName(service));

        this.getTransportScheme().add("Http");
        
        this.setUsername(factory.createSessionStartInfoContractUsername(HpcJava.user));
        this.setPassword(factory.createSessionStartInfoContractPassword(HpcJava.pass));
        
        this.setRuntime(3600);

        this.setShareSession(false);
    }    
    
    
    /**
     * Gets the headnode value
     * @return headnode value
     */
    public String headnode()
    {
        return headnode;
    }
    
    /**
     * Gets the Job Template
     * @return JobTemplate value
     */
    public String jobTemplate()
    {
        return getJobTemplate().getValue();
    }
    
    /**
     * Gets the number of maximum units (cores) to allocate
     * @return  maximumUnits value
     */
    public Integer maxUnits()
    {
        return getMaxUnits().getValue();
    }
    
    /**
     * Gets the number of minimum units (cores) to allocate
     * @return  minUnits value
     */
    public Integer minUnits()
    {
        return getMinUnits().getValue();
    }
    
    /**
     * Gets the node group string
     * @return NodeGroupsStr value
     */
    public String nodeGroupsStr()
    {
        return getNodeGroupsStr().getValue();
    }
    
    /**
     * Gets the plain text password value to be passed over SSL
     * @return plain text password value
     */
    public String password()
    {
        return getPassword().getValue();
    }
    
    /**
     * Gets the priority of the job
     * @return priority value
     */
    public JobPriority priority()
    {
        return getPriority().getValue();
    }
    
    /**
     * gets the requested nodes string
     * @return  RequestedNodesStr value
     */
    public String requestedNodesStr()
    {
        return getRequestedNodesStr().getValue();
    }
    
    /**
     * Gets the maximum runtime length in seconds
     * @return  Runtime value in seconds
     */
    public Integer runtime()
    {
        return getRuntime();
    }
    
    /**
     * Gets the Service Job Name (name of the job is different from service)
     * @return  ServiceJobName value
     */
    public String serviceJobName()
    {
        return getServiceJobName().getValue();
    }
    
    /**
     * Gets the Service name
     * @return  ServiceName value
     */
    public String serviceName()
    {
        return getServiceName().getValue();
    }
    
    /**
     * Gets the transport Scheme
     * @return  a list of TranportSchemes
     */
    public List<String> transportScheme()
    {
        return getTransportScheme();
    }
    
    /**
     * Gets the username
     * @return username value
     */
    public String username()
    {
        return getUsername().getValue();
    }
    
    
    /**
     * Sets the headnode to connect to
     * @param headnode  headnode to connect
     */
    public void setHeadnode(String headnode)
    {
        this.headnode = headnode;
    }
    
    /**
     * Sets the job template
     * @param template  Job template to use
     */
    public void setJobTemplate(String template)
    {
        setJobTemplate(factory.createSessionStartInfoContractJobTemplate(template));
    }
    
    /**
     * Sets the maximum units (cores) to allocate
     * @param maximumUnits  minimum number of cores to allocate
     */
    public void setMaxUnits(Integer maximumUnits)
    {
        setMaxUnits(factory.createSessionStartInfoContractMaxUnits(maximumUnits));
    }
    
    /**
     * Sets the minimum units (cores) to allocate
     * @param MinUnits  minimum number of cores to allocate
     */
    public void setMinUnits(Integer minUnits)
    {
        setMinUnits(factory.createSessionStartInfoContractMinUnits(minUnits));
    }
    
    /**
     * Sets the node groups to use
     * @param nodeGroups node groups string
     */
    public void setNodeGroupsStr(String nodeGroups)
    {
        setNodeGroupsStr(factory.createSessionStartInfoContractNodeGroupsStr(nodeGroups));
    }
    
    /**
     * Sets the password in plain text to be sent over SSL
     * @param password  password in plain text
     */
    public void setPassword(String password)
    {
        setPassword(factory.createSessionStartInfoContractPassword(password));
    }
    
    /**
     * Sets the project value
     * @param project   Project value
     */
    public void setServiceJobProject(String project)
    {
        setServiceJobProject(factory.createSessionStartInfoContractServiceJobProject(project));
    }
    
    /**
     * Sets the requested nodes string
     * @param nodes requestedNodes string
     */
    public void setRequestedNodesStr(String nodes)
    {
        setRequestedNodesStr(factory.createSessionStartInfoContractRequestedNodesStr(nodes));
    }
    
    /**
     * Sets the resourceUnit type
     * @param unit  JobUnitType enum
     */
    public void setResourceUnitType(JobUnitType unit)
    {
        setResourceUnitType(factory.createSessionStartInfoContractResourceUnitType(unit));
    }
    
    /**
     * Sets the jobname
     * @param jobname   name of the job
     */
    public void setServiceJobName(String jobname)
    {
        setServiceJobName(factory.createSessionStartInfoContractServiceJobName(jobname));
    }
    
    /**
     * Sets the service name to use
     * @param servicename   name of the service
     */
    public void setServiceName(String servicename)
    {
        setServiceName(factory.createSessionStartInfoContractServiceName(servicename));
    }
    
    /**
     * Sets the username to use
     * @param username  username    
     */     
    public void setUsername(String username)
    {
        setUsername(factory.createSessionStartInfoContractUsername(username));
    }
    
    /**
     * Adds a transportscheme to the end of the list
     * @param ts    TransportScheme enum
     */
    public void addTransportScheme(TransportScheme ts)
    {
        getTransportScheme().add(ts.getName());
    }
    
    /**
     * Replaces the transportScheme list with a new list with only TransportScheme ts
     * @param ts    TransportScheme enum
     */
    public void setTransportScheme(TransportScheme ts)
    {
        this.transportScheme = new ArrayList<String>();
        this.transportScheme.add(ts.getName());
    }

	
	/**
	 * Returns the allocation grow load ratio threshold
	 * @return <code>AllocationGrowLoadRatioThreshold</code> value
	 * @see #allocationShrinkLoadRatioThreshold() 
	 */
	public int allocationGrowLoadRatioThreshold()
	{
		return this.getAllocationGrowLoadRatioThreshold().getValue();
	}
	
	/**
	 * Returns the allocation shrink load ratio threshold
	 * @return <code>AllocationShrinkLoadRatioThreshold</code> value
	 */
	public int allocationShrinkLoadRatioThreshold()
	{
		return this.getAllocationShrinkLoadRatioThreshold().getValue();
	}
	
	/**
	 * Returns the client connection timeout
	 * @return <code>ClientConnectionTimeout</code> value
	 * @deprecated <code>ClientConnectionTimeout</code> value is now overwritten by <code>SessionIdleTimeout</code>
	 * @see #sessionIdleTimeout()
	 */
	public int clientConnectionTimeout()
	{
		return this.getClientConnectionTimeout().getValue();
	}
	
	/**
	 * Returns the client idle timeout
	 * @return	<code>ClientIdleTimeout</code> value
	 */
	public int clientIdleTimeout()
	{
		return this.getClientIdleTimeout().getValue();
	}
	
	/**
	 * Returns messages throttle start threshold
	 * @return	<code>MessagesThrottleStartThreshold</code> value
	 */
	public int messagesThrottleStartThreshold()
	{
		return this.getMessagesThrottleStartThreshold().getValue();
	}
	
	/**
	 * Returns the messages throttle stop threshold
	 * @return	<code>MessagesThrottleStopThreshold</code> value
	 */
	public int messagesThrottleStopThreshold()
	{
		return this.getMessagesThrottleStopThreshold().getValue();
	}
	
	/**
	 * Returns the session idle timeout
	 * @return	<code>SessionIdleTimeout</code> value
	 */
	public int sessionIdleTimeout()
	{
		return this.getSessionIdleTimeout().getValue();
	}
	
	/**
	 * Sets the allocation grow load ratio threshold
	 * @param value This value must be greater than or equal to <code>AllocationShrinkLoadRatioThreshold</code>
	 * @see #allocationShrinkLoadRatioThreshold()
	 */
	public void setAllocationGrowLoadRatioThreshold(int value)
	{
		factory.createSessionStartInfoContractAllocationGrowLoadRatioThreshold(value);
	}
	
	/**
	 * Sets the allocation shrink load ratio threshold
	 * @param value This value must be less than or equal to <code>AllocationGrowLoadRatioThreshold</code>
	 * @see #allocationGrowLoadRatioThreshold()
	 */
	public void setAllocationShrinkLoadRatioThreshold(int value)
	{
		factory.createSessionStartInfoContractAllocationShrinkLoadRatioThreshold(value);
	}
	
	/**
	 * Sets the client connection timeout
	 * @param value This value must be greater than zero
	 * @deprecated	This value gets overwritten by SessionIdleTimeout
	 * @see #sessionIdleTimeout()
	 */
	public void setClientConnectionTimeout(int value)
	{
		factory.createSessionStartInfoContractClientConnectionTimeout(value);
	}
	
	/**
	 * Sets the client idle timeout
	 * @param value The value must be greater than zero
	 */
	public void setClientIdleTimeout(int value)
	{
		factory.createSessionStartInfoContractClientIdleTimeout(value);
	}
	
	/**
	 * Sets the messages throttle start threshold
	 * @param value The value must be less than or greater than <code>MessagesThrottleStopThreshold</code>
	 * @see #messagesThrottleStopThreshold()
	 */
	public void setMessagesThrottleStartThreshold(int value)
	{
		factory.createSessionStartInfoContractMessagesThrottleStartThreshold(value);
	}
	
	/**
	 * Sets the messages throttle stop threshold
	 * @param value The value must be greater than or less than <code>MessagesThrottleStartThreshold</code>
	 * @see #messagesThrottleStartThreshold()
	 */
	public void setMessagesThrottleStopThreshold(int value)
	{
		factory.createSessionStartInfoContractMessagesThrottleStopThreshold(value);
	}
	
	/**
	 * Sets the session idle timeout
	 * @param value This value must greater than zero 
	 */
	public void setSessionIdleTimeout(int value)
	{
		factory.createSessionStartInfoContractSessionIdleTimeout(value);
	}

	


}

