using System;
using Newtonsoft.Json;
#if WASM
   using CommonHelpers.WASM;
   using BookRegistry.Client.DB;
namespace BookRegistry.Client {
#else // !WASM:
   using CommonHelpers;
   using BookRegistry.Server.DB;
namespace BookRegistry.Server {
#endif // !WASM
//==================================================================================================

public class AuthorizeUser_Response: GeneralApiResponse
{
   public ServiceUser_Info UserInfo {
      get => Get( NUserInfo );
      set => NUserInfo = value; } internal ServiceUser_Info? NUserInfo;

   public string RoleName {
      get => Get( NRoleName );
      set => NRoleName = value; } internal string? NRoleName;

   public DateTime LoginUtc {
      get => Value( NLoginUtc );
      set => NLoginUtc = value; } internal DateTime? NLoginUtc;

   public GeneratedToken_Info AccessToken {
      get => Get( NAccessToken );
      set => NAccessToken = value; } internal GeneratedToken_Info? NAccessToken;

   public GeneratedToken_Info RefreshToken {
      get => Get( NRefreshToken );
      set => NRefreshToken = value; } internal GeneratedToken_Info? NRefreshToken;

   public AuthorizeUser_Response() {}
   public AuthorizeUser_Response(GeneralApiResponse simpleResponse)
   : base( simpleResponse ) {}
#if SERVER
   internal AuthorizeUser_Response( ServiceUser_Info userInfo )
   {
      string
         userName = userInfo.LoginName,
         roleName = userInfo.IsAdministrator ?
            ServiceRoleNames.Administrator : ServiceRoleNames.General;
      UserInfo = userInfo;
      RoleName = roleName;
      LoginUtc = DateTime.UtcNow;
      AccessToken = new GeneratedToken_Info( userName, roleName );
      RefreshToken = new GeneratedToken_Info( userName, roleName, true );
   }
#endif // SERVER
} // AuthorizeUser_Response

//==================================================================================================

public class AuthorizeUser_Args: ApiArgumentsBase
{
   public string LoginName {
      get => Get( NLoginName );
      set => NLoginName = value; } internal string? NLoginName;

   public string Password {
      get => Get( NPassword );
      set => NPassword = value; } internal string? NPassword;
} // AuthorizeUser_Args

//==================================================================================================
} // BookRegistry.Client/Server
