using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using MarketDataServer.Authorization;

namespace MarketDataServer.Controllers
{
  public class AuthorizationController : ApiController
  {
    public String GetToken(String user)
    {
      Console.WriteLine(String.Format("[{0:G}][AuthorizationController::Authorize]",DateTime.Now));
      if(null==user)return null;
      user=Authorizations.Xor(user,5);
      Console.WriteLine(String.Format("[{0:G}][Login requested for user '{1}']",DateTime.Now, user));
      if(!Authorizations.GetInstance().IsValidUser(user))
      {
        Console.WriteLine(String.Format("[{0:G}][User '{1}' is not authorized]", DateTime.Now,user));
        return null;
      }
      String accessToken= Authorizations.GetInstance().GetAuthenticationToken();
      Console.WriteLine(String.Format("[{0:G}][Access token granted for user {1} : {2}]",DateTime.Now ,user, accessToken));
      return accessToken;

    }
  }
}
