using System;
#if WASM
   using CommonHelpers.WASM;
namespace BookRegistry.Client.DB {
#else // !WASM:
   using System.Threading.Tasks;
   using CommonHelpers;
namespace BookRegistry.Server.DB {
#endif // !WASM

//**************************************************************************************************
/// <summary>
/// Weather forecast summaries selection (stored procedure)
/// </summary>
public static class GetWeatherForecastSummaries_SP {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*
public static readonly Guid
   //Status_ = SPCommonStatuses.,
   //Status_ = new Guid( "" ),
*/
#if SERVER
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public const string Name = "BKRG::GetWeatherForecastSummaries";
public static HSPResult<ForecastSummary_Item>
   InvalidResult => new HSPResult<ForecastSummary_Item>();
//==================================================================================================

public static async Task<(HSPResult<ForecastSummary_Item>,string? Message)>
   EXEC_A( DateTime dateFrom, bool simulateError=false )
{
   using (new HSP(Name))
   {
      await HSP.Connect_A();
      var ( rp, cmd ) =  HSP.PrepareCommand(
         HSqlParam.In( "DateFrom", dateFrom ),
         HSqlParam.In( "SimulateError", simulateError ) );
      var list = await HSP.DoReaderCommand_A<ForecastSummary_Item>( cmd );
      string? message = null;
/*
      var list = await HSP.DoReaderCommandVerify_A<ForecastSummary_Item>( rp, cmd );
      message = HSP.OutMessage( rp );
      if ( list.Count == 0 && message == null )
         throw HDBExceptionsSPAuto.InconsistentResult;
*/
//*
      if ( HSP.Success( rp ) )
      {
         if ( list == null )
            throw HDBExceptionsSPAuto.ExpectedResultSetWasNotReceived;
         message = HSP.OutMessage( rp );
         if ( list.Count == 0 && message == null )
            throw HDBExceptionsSPAuto.InconsistentResult;
      }
//*/
      return ( new HSPResult<ForecastSummary_Item>( rp, list ), message );
   }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#endif // SERVER
} // GetWeatherForecastSummaries_SP
//**************************************************************************************************

/// <summary>
/// Result set (model)
/// </summary>
public class ForecastSummary_Item: ResultSetItemBase
{
   public DateTime Date {
      get => Value( NDate );
      set => NDate = value; } internal DateTime? NDate = _DT();

   public string Summary {
      get => Get( NSummary );
      set => NSummary = value; } internal string? NSummary = _NS();

   public int TemperatureC {
      get => Value( NTemperatureC );
      set => NTemperatureC = value; } internal int? NTemperatureC = _INT_( "Temperature" );

   public int TemperatureF =>
      32 + (int)(TemperatureC / 0.5556);

   public ForecastSummary_Item ForecastSummary_DuplicateItem() =>
      (ForecastSummary_Item)MemberwiseClone();
} // ForecastSummary_Item

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