using System.Globalization;
using System.Text;

namespace ZuluTradingSampleApp.Trading
{
    public class ZuluTradingRequestGeneratorImpl : IZuluTradingRequestGenerator
    {
        public string GetOpenMarketRequest(string currencyName, double lots, bool buy, double requestedPrice, string uniqueId)
        {
            StringBuilder sb = new StringBuilder("open/market/");
            sb.Append("?");
            sb.Append("currencyName=");
            sb.Append(currencyName);
            sb.Append("&lots=");
            sb.Append(lots.ToString(CultureInfo.InvariantCulture));
            sb.Append("&buy=");
            sb.Append(buy);
            sb.Append("&requestedPrice=");
            sb.Append(requestedPrice.ToString(CultureInfo.InvariantCulture));
            sb.Append("&uniqueId=");
            sb.Append(uniqueId);
            return sb.ToString();
        }

        public string GetCloseMarketRequest(string currencyName, double lots, bool buy, double requestedPrice, string uniqueId)
        {
            StringBuilder sb = new StringBuilder("close/market/");
            sb.Append("?");
            sb.Append("currencyName=");
            sb.Append(currencyName);
            sb.Append("&buy=");
            sb.Append(buy);
            sb.Append("&lots=");
            sb.Append(lots.ToString(CultureInfo.InvariantCulture));
            sb.Append("&uniqueId=");
            sb.Append(uniqueId);
            sb.Append("&requestedPrice=");
            sb.Append(requestedPrice.ToString(CultureInfo.InvariantCulture));
            return sb.ToString();
        }

        public string GetOpenOrderRequest(string currencyName, double lots, bool buy, double requestedPrice, string uniqueId)
        {
            StringBuilder sb = new StringBuilder("open/pending/");
            sb.Append("?");
            sb.Append("currencyName=");
            sb.Append(currencyName);
            sb.Append("&lots=");
            sb.Append(lots.ToString(CultureInfo.InvariantCulture));
            sb.Append("&buy=");
            sb.Append(buy);
            sb.Append("&requestedPrice=");
            sb.Append(requestedPrice.ToString(CultureInfo.InvariantCulture));
            sb.Append("&uniqueId=");
            sb.Append(uniqueId);
            return sb.ToString();
        }

        public string GetCancelOrderRequest(string currencyName, double lots, bool buy, string uniqueId)
        {
            StringBuilder sb = new StringBuilder("close/pending/");
            sb.Append("?");
            sb.Append("currencyName=");
            sb.Append(currencyName);
            sb.Append("&lots=");
            sb.Append(lots.ToString(CultureInfo.InvariantCulture));
            sb.Append("&buy=");
            sb.Append(buy);
            sb.Append("&uniqueId=");
            sb.Append(uniqueId);
            return sb.ToString();
        }
        
        public string GetUpdateLimitRequest(string currencyName, double lots, bool isBuy, double limitValue, string uniqueId)
        {
            StringBuilder sb = new StringBuilder("update/limit/");
            sb.Append("?");
            sb.Append("currencyName=");
            sb.Append(currencyName);
            sb.Append("&lots=");
            sb.Append(lots.ToString(CultureInfo.InvariantCulture));
            sb.Append("&buy=");
            sb.Append(isBuy);
            sb.Append("&uniqueId=");
            sb.Append(uniqueId);
            sb.Append("&limitValue=");
            sb.Append(limitValue.ToString(CultureInfo.InvariantCulture));
            return sb.ToString();
        }

        public string GetUpdateStopRequest(string currencyName, double lots, bool isBuy, double stopValue, string uniqueId)
        {
            StringBuilder sb = new StringBuilder("update/stop/");
            sb.Append("?");
            sb.Append("currencyName=");
            sb.Append(currencyName);
            sb.Append("&lots=");
            sb.Append(lots.ToString(CultureInfo.InvariantCulture));
            sb.Append("&buy=");
            sb.Append(isBuy);
            sb.Append("&uniqueId=");
            sb.Append(uniqueId);
            sb.Append("&stopValue=");
            sb.Append(stopValue.ToString(CultureInfo.InvariantCulture));
            return sb.ToString();
        }

        public string GetUpdateTrailingStopRequest(string currencyName, bool buy, double lots, string uniqueId, int trailingStopValue)
        {
            StringBuilder sb = new StringBuilder("update/stop/trailing/");
            sb.Append("?");
            sb.Append("currencyName=");
            sb.Append(currencyName);
            sb.Append("&lots=");
            sb.Append(lots);
            sb.Append("&buy=");
            sb.Append(buy);
            sb.Append("&uniqueId=");
            sb.Append(uniqueId);
            sb.Append("&trailingStopValue=");
            sb.Append(trailingStopValue);
            return sb.ToString();
        }

        public string GetUpdateTrailingStopConditionRequest(string currencyName, bool buy, double lots, string uniqueId, int trailingStopValue, int tralingStopConditionPips)
        {
            StringBuilder sb = new StringBuilder("update/stop/trailingCondition/");
            sb.Append("?");
            sb.Append("currencyName=");
            sb.Append(currencyName);
            sb.Append("&lots=");
            sb.Append(lots);
            sb.Append("&buy=");
            sb.Append(buy);
            sb.Append("&uniqueId=");
            sb.Append(uniqueId);
            sb.Append("&trailingStopValue=");
            sb.Append(trailingStopValue);
            sb.Append("&trailingStopConditionPipsValue=");
            sb.Append(tralingStopConditionPips);
            return sb.ToString();
        }

        public string GetUpdateEntryRateRequest(string currencyName, double lots, bool isBuy, double entryRate, string uniqueId)
        {
            StringBuilder sb = new StringBuilder("update/entry/");
            sb.Append("?");
            sb.Append("currencyName=");
            sb.Append(currencyName);
            sb.Append("&lots=");
            sb.Append(lots.ToString(CultureInfo.InvariantCulture));
            sb.Append("&buy=");
            sb.Append(isBuy);
            sb.Append("&uniqueId=");
            sb.Append(uniqueId);
            sb.Append("&entryValue=");
            sb.Append(entryRate.ToString(CultureInfo.InvariantCulture));
            return sb.ToString();
        }

        public string GetOpenTradesRequest()
        {
            StringBuilder sb = new StringBuilder("getOpen/");
            return sb.ToString();
        }

        public string GetTradingConfigurationRequest() {
		    StringBuilder sb = new StringBuilder("getTradingConfiguration/");
		    return sb.ToString();
    	}

        public string GetProviderStatisticsRequest() {
		    StringBuilder sb = new StringBuilder("getProviderStatistics/");
		    return sb.ToString();
	    }

        public string GetHistoryRequest(string startDate, string endDate)
        {
		    StringBuilder sb = new StringBuilder("getHistory/");
		    sb.Append("?");
            sb.Append("startDate=");
            sb.Append(startDate);
            sb.Append("&endDate=");
            sb.Append(endDate);
		    return sb.ToString();
        }
    }
}
