using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.RazorPages;

using CommonHelpers;

using MyFlat.DB;

namespace MyFlat {

//**************************************************************************************************
/// <summary>
/// Authorization page model (home page for MVC)
/// </summary>
public class HomePageModel: PageModel {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public readonly PageModelData? Data;
public readonly AuthorizationInfo? AuthorizationInfo;
[HOptionalValue]
public readonly AccountInfo_Item? AccountProps;
public bool AreLoginInputErrors;
[HOptionalValue]
public HomePageInputBase? InputPreserve;

public PageModelData DataNN => Data.NN();
public AuthorizationInfo AuthorizationInfoNN => AuthorizationInfo.NN();
public AccountInfo_Item AccountPropsNN => AccountProps.NN();
public HomePageInputBase InputPreserveNN => InputPreserve.NN();

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

public HomePageModel(HomeController controller)
{
   Data = new PageModelData( controller );
   var app = new App( controller );
   if ( app.IsUserSessionOpen )
   {
      var sd = app.SessionData;
      AuthorizationInfo = sd.AuthorizationInfo;
      AccountProps = sd.AccountProps;
   }
}
public HomePageModel(HomeController controller,List<string> errorMessages)
{
   Data = new PageModelData( controller, errorMessages );
   var app = new App( controller );
   if ( app.IsUserSessionOpen )
   {
      var sd = app.SessionData;
      AuthorizationInfo = sd.AuthorizationInfo;
      AccountProps = sd.AccountProps;
   }
}
public HomePageModel(HomeController controller,string errorMessage)
{
   Data = new PageModelData( controller, errorMessage );
   var app = new App( controller );
   if ( app.IsUserSessionOpen )
   {
      var sd = app.SessionData;
      AuthorizationInfo = sd.AuthorizationInfo;
      AccountProps = sd.AccountProps;
   }
}

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

public static HomePageModel ServerError(HomeController controller,string errorMessage) =>
   new HomePageModel( controller, MSG.ServerError( errorMessage ) );

public static HomePageModel ServerError(HomeController controller,Exception e) =>
   new HomePageModel( controller, MSG.ServerError( e ) );

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HomePageModel
//**************************************************************************************************

} // MyFlat
