using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using MarketData.MarketDataModel;
using MarketData.DataAccess;
using MarketDataServer.Authorization;
using MarketData.Generator;

namespace MarketDataServer.Controllers
{
  //http://localhost:8000/api/PreMarket/GetAvailableMarketDates?&market=S&P
  public class PreMarketController:ApiController
  {
    public IEnumerable<DateTime> GetAvailableMarketDates(String token,String market)
    {
      Console.WriteLine(String.Format("[{0:G}][PreMarketController::GetAvailableMarketDates]{1}",DateTime.Now,market));
      if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
      return PremarketDA.GetAvailableMarketDates(market);
    }
    public IEnumerable<String> GetAvailableMarkets(String token)
    {
      Console.WriteLine(String.Format("[{0:G}][PreMarketController::GetAvailableMarkets]",DateTime.Now));
      if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
      return PremarketDA.GetDistinctMarkets();
    }
    public IEnumerable<PremarketElement> GetLatestPremarketData(String token,String market,DateTime marketDate)
    {
      Console.WriteLine(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);
    }
  }
}

