//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// DataHelpers.SQL satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using u = user_rtx;

namespace DataHelpers.SQL {

//**************************************************************************************************
[h_db_orm_type]
public class HSPCommandResult
{
   public HSPResultStateForm StateForm { get; }
   public bool IsAvailable => StateForm==HSPResultStateForm.Available;

   /// <exception cref="InvalidOperationException" />
   public bool Success
   {
      get {
         VerifyAvailable();
         return _success;
      }
   }
   /// <exception cref="InvalidOperationException" />
   [u.opt_value]
   public Guid Status
   {
      get {
         VerifyAvailable();
         return _status;
      }
   }
   /// <exception cref="InvalidOperationException" />
   public string? OutMessage
   {
      get {
         VerifyAvailable();
         return _outMessage;
      }
   }
   /// <exception cref="InvalidOperationException" />
   public string ErrorMessage =>
      Success ? HSPResultErrorMsg.NoError :
         OutMessage ?? HSPResultErrorMsg.ErrorMessageNotProvided;

   /// <exception cref="InvalidOperationException" />
   [u.strict_result]
   public string StrictOutMessage =>
      OutMessage ?? throw HSPResultError.OutMessageUnavailable;

   public HSPCommandResult() =>
      StateForm = HSPResultStateForm.Invalid;

   public HSPCommandResult( HSPResultParameters resultParams )
   {
      StateForm = HSPResultStateForm.Available;
      _success = HSP.Success( resultParams );
      _status = HSP.Status( resultParams );
      _outMessage = HSP.OutMessage( resultParams );
   }
   public HSPCommandResult( bool success, Guid status, string? outMessage )
   {
      StateForm = HSPResultStateForm.Available;
      _success = success;
      _status = status;
      _outMessage = outMessage;
   }

   /// <exception cref="InvalidOperationException" />
   public void VerifyAvailable()
   {
      if ( StateForm != HSPResultStateForm.Available )
         throw HSPResultError.Unavailable;
   }

   readonly bool _success;
   readonly Guid _status;
   readonly string? _outMessage;

} // HSPCommandResult
//**************************************************************************************************

//**************************************************************************************************
[h_db_orm_type]
public class HSPCommandResultRV
{
   public HSPResultStateForm StateForm { get; }
   public bool IsAvailable => StateForm==HSPResultStateForm.Available;

   /// <exception cref="InvalidOperationException" />
   public int RetValue
   {
      get {
         VerifyAvailable();
         return _retValue;
      }
   }
   /// <exception cref="InvalidOperationException" />
   [u.opt_value]
   public Guid Status
   {
      get {
         VerifyAvailable();
         return _status;
      }
   }
   /// <exception cref="InvalidOperationException" />
   public string? OutMessage
   {
      get {
         VerifyAvailable();
         return _outMessage;
      }
   }
   /// <exception cref="InvalidOperationException" />
   public string OutMessageAsError =>
      OutMessage ?? HSPResultErrorMsg.ErrorMessageNotProvided;

   /// <exception cref="InvalidOperationException" />
   [u.strict_result]
   public string StrictOutMessage =>
      OutMessage ?? throw HSPResultError.OutMessageUnavailable;

   public HSPCommandResultRV() =>
      StateForm = HSPResultStateForm.Invalid;

   public HSPCommandResultRV( HSPResultParameters resultParams )
   {
      StateForm = HSPResultStateForm.Available;
      _retValue = HSP.RetValue( resultParams );
      _outMessage = HSP.OutMessage( resultParams );
      _status = HSP.Status( resultParams );
   }
   public HSPCommandResultRV( int retValue, Guid status, string? outMessage )
   {
      StateForm = HSPResultStateForm.Available;
      _retValue = retValue;
      _status = status;
      _outMessage = outMessage;
   }

   /// <exception cref="InvalidOperationException" />
   public void VerifyAvailable()
   {
      if ( StateForm != HSPResultStateForm.Available )
         throw HSPResultError.Unavailable;
   }

   readonly int _retValue;
   readonly Guid _status;
   readonly string? _outMessage;

} // HSPCommandResultRV
//**************************************************************************************************

} // DataHelpers.SQL
