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

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