using MarketData.MarketDataModel;
using MarketData.DataAccess;
using MarketDataServer.Authorization;
using MarketData;
using Microsoft.AspNetCore.Mvc;
using LogLevel = MarketData.LogLevel;
using MarketData.Utils;

namespace MarketDataServer.Controllers
{
  [ApiController]
  [Route("api/[controller]/[action]")]
  public class EconomicIndicatorsController : ControllerBase
	{
//http://localhost:8000/api/EconomicIndicators/GetDistinctEconomicIndicators
		[HttpGet(Name = "GetDistinctEconomicIndicators")]
		public IEnumerable<String> GetDistinctEconomicIndicators(String token)
		{
		  Profiler profiler = new Profiler();
		  try
			{
        MDTrace.WriteLine(LogLevel.DEBUG,$"Start");
				if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
        return EconomicIndicatorDA.GetDistinctIndicators();
			}
      catch(Exception exception)
      {
        MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
        return null;
      }	
      finally
      {
        MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()} (ms)");
      }			
		}

		[HttpGet(Name = "GetEconomicIndicators")]
		public IEnumerable<EconomicIndicator> GetEconomicIndicators(String token,String indicatorCode)
		{
		  Profiler profiler = new Profiler();
		  try
			{
        MDTrace.WriteLine(LogLevel.DEBUG,$"Start");
				if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
				EconomicIndicators economicIndicators=EconomicIndicatorDA.GetEconomicIndicators(indicatorCode);
				return economicIndicators;
			}
			catch(Exception exception)
			{
        MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
        return null;
			}
      finally
      {
        MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()} (ms)");
      }			
		} 
	}
}
