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

//**************************************************************************************************
/// <summary>
///  (stored procedure)
/// </summary>
public static class _SP {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*
public static readonly Guid
   //Status_ = SPCommonStatuses.,
   //Status_ = new Guid( "" ),
*/
#if SERVER
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public const string Name = "BKRG::";
public static HSPResult_2<_Item,_Item>
   InvalidResult => new HSPResult_2<_Item,_Item>();
//==================================================================================================

public static async Task<HSPResult_2<_Item,_Item>> EXEC_A( ... )
{
   return await HSPPerformer.Do_A<_Item>(Name,async delegate{
      var ( rp, cmd ) = HSP.PrepareCommand(
         HSqlParam.In( "",  ),
         HSqlParam.In( "",  ),
         HSqlParam.In( "",  ) );
      List<_Item>? list_1 = null;
      List<_Item>? list_2 = null;
      using (var rdr = await HSPCommandDispose.ExecuteReader_A( cmd ))
      if ( HSP.Success( rp ) )
      {
         list_1 = await HSP.RSetToList_A<_Item>( 1, rdr );
/*
         if ( list_1.Count != 1 )
            throw HDBExceptionsSPAuto.ExactlyOneRecordWasExpectedIn1stRSet;
*/
         if ( !rdr.NextResult() )
            throw HDBExceptionsSPAuto.SecondResultSetWasExpected;
         list_2 = await HSP.RSetToList_A<_Item>( 2, rdr );
/*
         if ( list_2.Count != 1 )
            throw HDBExceptionsSPAuto.ExactlyOneRecordWasExpectedIn2ndRSet;
*/
      }
      return new HSPResult_2<_Item,_Item>( rp, list_1, list_2 );
   });
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#endif // SERVER
} // _SP
//**************************************************************************************************

/// <summary>
/// Result set #1 (model)
/// </summary>
public class _Item: ResultSetItemBase
{
   public   {
      get => Get( N );
      set => N = value; } internal ? N = _ACCESSOR();

   public   {
      get => Value( N );
      set => N = value; } internal ? N = _ACCESSOR();

   public ?  { get; set; } = ACCESSOR_N();

   public _Item _Duplicate() =>
      (_Item)MemberwiseClone();
} // _Item

/// <summary>
/// Result set #2 (model)
/// </summary>
public class _Item: ResultSetItemBase
{
   public   {
      get => Get( N );
      set => N = value; } internal ? N = _ACCESSOR();

   public   {
      get => Value( N );
      set => N = value; } internal ? N = _ACCESSOR();

   public ?  { get; set; } = ACCESSOR_N();

   public _Item _Duplicate() =>
      (_Item)MemberwiseClone();
} // _Item

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