package transaction;

import transaction.DigitalSignature;
import data.Derivative;

public class Create extends Transaction
{
	private String playerName;
	private Derivative derivative;
	private DigitalSignature digitalSignature;

	/**
	 * default constructor
	 * 
	 * @exception RuntimeException
	 */
	public Create()
	{
		throw new RuntimeException( "Unable to instantiate default Create object." );
	}
	
	/**
	 * constructor
	 * 
	 * @param pPlayerName
	 * @param pDerivative
	 * @param pDigitalSignature
	 */
	public Create( String pPlayerName, Derivative pDerivative )
	{
		setPlayerName( pPlayerName );
		setDerivative( pDerivative );
	}

	/*========================================================================
	|                           getters and setters
	+-----------------------------------------------------------------------*/
	
	/**
	 * set the playerName field to the given String
	 * 
	 * @param pPlayerName : String to be set as playerName
	 */
	void setPlayerName( String pPlayerName )
	{
		playerName = pPlayerName;
	}

	/**
	 * set the derivative field to the given Derivative
	 * 
	 * @param pDerivative : Derivative to be set as derivative
	 */
	void setDerivative( Derivative pDerivative )
	{
		derivative = pDerivative;
	}

	/**
	 * set the digitalSignature field to the given DigitalSignature
	 * 
	 * @param pDigitalsignature : DigitalSignature to be set as the 
	 * 	digital signature
	 */
	void setDigitalSignature( DigitalSignature pDigitalSignature )
	{
		digitalSignature = pDigitalSignature;
	}

	/** 
	 * get the name of the player
	 * 
	 * @return String : name of the player
	 */
	public String getPlayerName()
	{
		return playerName;
	}

	/**
	 * get the derivative
	 * 
	 * @return Derivative 
	 */
	public Derivative getDerivative()
	{
		return derivative;
	}

	/**
	 * get the digital signature
	 * 
	 * @return DigitalSignature
	 */
	public DigitalSignature getDigitalSignature()
	{
		return digitalSignature;
	}
	
	/*-----------------------------------------------------------------------
	|                       end getters and setters
	+======================================================================*/
	
	/**
	 * generate the xml representation of a create transaction
	 * 
	 * @return String
	 */
	public String generateXML()
	{
		return new String( "<trans>\n<create></create>\n<playerName>" + playerName + "</playerName>\n" + derivative.generateXML() + "</trans>\n");
	}
	
	/**
	 * print the XML representation of this class to the console
	 */
	public void print()
	{
		System.out.println( generateXML() );
	}
	
	/**
	 * determine if this transaction is of the given type
	 */
	public boolean sameType( String pTransactionType )
	{
		return ( pTransactionType.compareTo( "Create" ) == 0 );
	}
}