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/Price
//http://localhost:8000/api/Price/GetPrices?&symbol=MIDD&days=5
//http://73.245.214.234:8000/api/Price/GetPrices?&symbol=MIDD&days=5
  public class PriceController : ApiController
  {
    public IEnumerable<Price> GetPrices(String token, String symbol, int days)
    {
      Console.WriteLine(String.Format("[{0:G}][PriceController::GetPrices]", DateTime.Now));
      if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
      return PricingDA.GetPrices(symbol, days);
    }
    public BollingerBands GetBollingerBands(String token,String symbol,int dayCount)
    {
      Console.WriteLine(String.Format("[{0:G}][PriceController::GetBollingerBands]", DateTime.Now));
      if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
      Prices prices=PricingDA.GetPrices(symbol,dayCount);
      BollingerBands bollingerBands=BollingerBandGenerator.GenerateBollingerBands(prices);
      return bollingerBands;
    }
    public DateTime GetLatestPricingDate(String token)
    {
      Console.WriteLine(String.Format("[{0:G}][PriceController::GetLatestPricingDate]", DateTime.Now));
      if (!Authorizations.GetInstance().IsAuthorized(token)) return DateTime.MinValue;
      DateTime latestPricingDate=PricingDA.GetLatestDate();
      return latestPricingDate;
    }
    public String GetCompanyNameForSymbol(String token, String symbol)
    {
      Console.WriteLine(String.Format("[{0:G}][PortfolioController::GetCompanyNameForSymbol]", DateTime.Now));
      if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
      String companyName=PricingDA.GetNameForSymbol(symbol);
      return companyName;
    }
  }
}
