using ITVisions;
using MiracleListAPI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Web
{
 public static class AppState
 {
  public static string ClientID= "11111111-1111-1111-1111-111111111111";
  public static string UserName = "HS";
  public static string Password = "HS";
 

  public static string Token { get {
    //if (LoginInfo == null) return "83a8db79-3ca0-44ae-b309-c5c99699ddc1"; 
    return LoginInfo?.Token; } }
  public static LoginInfo LoginInfo;
  //private static AppState _Current { get; set; }
  public static MiracleListAPI.MiracleListProxy Proxy = new MiracleListProxy(new System.Net.Http.HttpClient());
  //public static AppState Current
  //{
  // get
  // {
  //  if (_Current == null) _Current = new AppState();
  //  return _Current;
  // }
  //}


  //public AppState()
  //{
  // //Init();
  //}
  static async public Task Init()
  {
   if (AppState.LoginInfo != null) return;
    Console.WriteLine("AppState: init");
   var loginInfo = new LoginInfo();
   loginInfo.ClientID = AppState.ClientID;
   loginInfo.Username = AppState.UserName;
   loginInfo.Password = AppState.Password;

   AppState.LoginInfo = await Proxy.LoginAsync(loginInfo);
   Console.WriteLine("AppState: LoginInfo");
   ObjectDumper.Write(AppState.LoginInfo);
  }
 }
}
