using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CurrencyExchangeLib
{
    public class CurrencyExchange
    {
        private string _vendor;
        private IVendorRateWebService _vendorRateService;

        public CurrencyExchange(IVendorRateWebService vendorRateService)
        {
            _vendorRateService = vendorRateService;
        }

        internal double MarkDown(double amount)
        {
            return amount * 0.98;
        }

        public Tuple<String, double> GetRate(string currency)
        {
            try
            {
                if (_vendor != null)
                {
                    var adjustedRate = MarkDown(_vendorRateService.GetExchange(_vendor, currency));
                    return new Tuple<string, double>(_vendor, adjustedRate);
                }
            }
            catch (ApplicationException)
            {
                return new Tuple<string, double>("", 0.0);
            }

            return new Tuple<string, double>("", 0.0);
        }

        internal void SetVendor(string vendor)
        {
            _vendor = vendor;
        }
    }
}
