package iis;


import java.rmi.Remote;
import java.rmi.RemoteException;


/*
 * This interface defines the functionality of the trusted agent. Possible
 * error constants and the path to the trusted agent are also provided.
 * This file has to be present in the same folder as your bidding server
 * since it is used for the dynamic proxy binding.
 *
 * You can reference the ERR_* constants directly since they are defined
 * statically.
 */
public interface AgentIF extends Remote
{
	/*
	 * The following constants indicate the bit position in the integer
	 * returned by requestTicket(...) and confirmBid(...). The returned
	 * value is smaller than TICKET_MIN (or 0 in the second case) if and
	 * only if there was an error during the method execution.
	 *
	 * You can use this bit mask to track the error. In order to compare
	 * a bit mask, use bitwise logical operations.
	 */
	static final int ERR_CREDENTIALFORMAT = 0;
	static final int ERR_BUYERNOTKNOWN = ERR_CREDENTIALFORMAT + 1;
	static final int ERR_PASSWORDWRONG = ERR_BUYERNOTKNOWN + 1;

	static final int ERR_VENDORNOTKNOWN = ERR_PASSWORDWRONG + 1;
	static final int ERR_IMPOSSIBLETRANSACTION = ERR_VENDORNOTKNOWN + 1;

	static final int ERR_ITEMFORMAT = ERR_IMPOSSIBLETRANSACTION + 1;

	static final int ERR_BIDINVALID = ERR_ITEMFORMAT + 1;
	static final int ERR_BIDALREADYREGISTERED = ERR_BIDINVALID + 1;

	static final int ERR_SQLERROR = ERR_BIDALREADYREGISTERED + 1;
	static final int ERR_UNKNOWNERROR = ERR_SQLERROR + 1;

	/* set exclusively by ticket confirmation method if ticket data is invalid */
	static final int ERR_TICKETINVALID = ERR_UNKNOWNERROR + 1;


	/* a valid ticket is always strictly greater than this number */
	static final int TICKET_MIN = 99999999;

 	/* location and namespace of the trusted agent */
	static final String TRUSTEDAGENTURI = "http://lsir-cis-pc1.epfl.ch:8001/TrustedAgent/agent";
	static final String NAMESPACEURI = "http://lsirwww.epfl.ch/";



	/**
	 * Request a ticket at the trusted agent. This method has to be called in
	 * order to authenticate and register your intended offer. Give all the
	 * necessary details and make sure to indicate the parameters in correct
	 * format.
	 *
	 * @param buyer		The group number representing the buyer (you!)
	 * @param password	The password that was assigned to you
	 * @param vendor	Group number representing the vendor of the desired item
	 * @param ticket	Ticket representing the item ID as listed in the
	 *			vendor's web shop
	 * @param bid		A floating point number indicating the price
	 *			you are willing to pay
	 * @param price		A floating point number indicating the article's
	 *			listed price
	 *
	 * @returns 		An integer representing the ticket number obtained
	 *			from the agent. Please remember that this number has
	 *			to be greater than TICKET_MIN. Otherwise it is a field
	 *			with corresponding ERR_* constant bit set to 1.
	 *			This should help you to track down errors.
	 */
	public int requestTicket(int buyer, String password, int vendor, String item, float bid, float price) throws RemoteException;


	/**
	 * Method used by the vendor to confirm a ticket. This method has to be
	 * called by the server since no transaction can be established without
	 * the server's confirmation.
	 *
	 * @param buyer		The group number representing the buyer
	 * @param vendor	Group number representing the vendor of the desired item
	 * @param ticket	Ticket representing the item ID as listed in the
	 *			vendor's web shop
	 * @param bid		A floating point number indicating the price
	 *			the vendor is willing to pay
	 * @param price		A floating point number indicating the article's
	 *			listed price
	 * @param ticket	The ticket received from the buyer.
	 *
	 * @returns		Method returns 0 upon successful confirmation.
	 * 			If the returned value is not 0, it is a bit field with the
	 * 			corresponding ERR_* constant bit set to 1.
	 */
	public int confirmBid(int buyer, int vendor, String item, float bid, float price, int ticket) throws RemoteException;
}

