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

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

public static async Task<(HSPCommandResult,Guid NewId)> EXEC_A(AddBook_Input input)
{
   using (new HSP(Name))
   {
      await HSP.Connect_A();
      var ( rp, cmd ) = input.BookSaving_PrepareCommand();
      var idParam = input.ID.HasValue ?
         HSqlParam.InOut( "ID", input.ID.Value ) :
         HSqlParam.Out( "ID", SqlDbType.UniqueIdentifier );
      cmd.Parameters.Add( idParam );
      await HSPCommandDispose.ExecuteNonQuery_A( cmd );
      var newId = HSP.Success( rp ) ?
         SPOutputReader.GUID( idParam ) :
         Guid.Empty;
      return ( new HSPCommandResult( rp ), newId );
   }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#endif // SERVER
} // AddBook_SP
//**************************************************************************************************

/// <summary>
/// Input parameters model as extension of “BookSaving_Input” (base model class)
/// </summary>
public class AddBook_Input: BookSaving_Input
{
// New book identifier here is optional:
   [JsonProperty(Order=1)]
   public Guid? ID { get; set; }
} // AddBook_Input

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