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

namespace MarketDataServer.Controllers
{
  //http://localhost:8000/api/PreMarket/GetAvailableMarketDates?&market=S&P
  [ApiController]
  [Route("api/[controller]/[action]")]    
  public class PreMarketController: ControllerBase
  {
    [HttpGet(Name = "GetAvailableMarketDates")]  
    public IEnumerable<DateTime> GetAvailableMarketDates(String token,String market)
    {
      MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PreMarketController::GetAvailableMarketDates]{1}",DateTime.Now,market));
      if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
      return PremarketDA.GetAvailableMarketDates(market);
    }

    [HttpGet(Name = "GetAvailableMarkets")] 
    public IEnumerable<String> GetAvailableMarkets(String token)
    {
      MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PreMarketController::GetAvailableMarkets]",DateTime.Now));
      if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
      return PremarketDA.GetDistinctMarkets();
    }

    [HttpGet(Name = "GetLatestPremarketData")] 
    public IEnumerable<PremarketElement> GetLatestPremarketData(String token,String market,DateTime marketDate)
    {
      MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PreMarketController::GetLatestPremarketData]{1},{2}",DateTime.Now,market,marketDate.ToShortDateString()));
      if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
      return PremarketDA.GetLatestPremarketData(market,marketDate);
    }
  }
}

