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;

namespace MarketDataServer.Controllers
{
  public class HeadlinesController : ApiController
  {
    public IEnumerable<Headline> GetLatestHeadlines(String token)
    {
      Console.WriteLine(String.Format("[{0:G}][HeadlinesController::GetLatestHeadlines]", DateTime.Now));
      if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
      return HeadlinesDA.GetLatestHeadlines();
    }
    public IEnumerable<String> GetHeadlineDates(String token)
    {
      Console.WriteLine(String.Format("[{0:G}][HeadlinesController::GetHeadlineDates]", DateTime.Now));
      if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
      List<string> headlineDates = HeadlinesDA.GetHeadlineDates();
      if(headlineDates.Count>0)headlineDates=headlineDates.Take(252).ToList();
      return headlineDates;
//      return HeadlinesDA.GetHeadlineDates();
    }
    public IEnumerable<Headline> GetHeadlines(String token,DateTime headlineDate)
    {
      Console.WriteLine(String.Format("[{0:G}][HeadlinesController::GetHeadliness(DateTime headlineDate)]", DateTime.Now));
      if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
      return HeadlinesDA.GetHeadlines(headlineDate);
    }
  }
}
