//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// CommonHelpers satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Collections.Generic;
using System.Data.SqlClient;

namespace CommonHelpers {

//**************************************************************************************************
[HDbOrmType]
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" />
   [HOptionalValue]
   public Guid Status
   {
      get {
         VerifyAvailable();
         return _Status_;
      }
   }
   /// <exception cref="InvalidOperationException" />
   [HOptionalValue]
   public string? OutMessage
   {
      get {
         VerifyAvailable();
         return _OutMessage_;
      }
   }
   /// <exception cref="InvalidOperationException" />
   [HNotNull]
   public string ErrorMessage =>
      Success ? HSPResultErrorMsg.NoError :
         OutMessage ?? HSPResultErrorMsg.ErrorMessageNotProvided;

   /// <exception cref="InvalidOperationException" />
   [HStrictResult]
   public string _OutMessage =>
      OutMessage ?? throw HSPResultError.OutMessageUnavailable;

   public HSPCommandResult() =>
      StateForm = HSPResultStateForm.Invalid;
   /// <exception cref="ArgumentNullException" />
   public HSPCommandResult( HSPResultParameters resultParams )
   {
      HArgChecking.VerifyNotNull( 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
//**************************************************************************************************

//**************************************************************************************************
[HDbOrmType]
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" />
   [HOptionalValue]
   public Guid Status
   {
      get {
         VerifyAvailable();
         return _Status_;
      }
   }
   /// <exception cref="InvalidOperationException" />
   [HOptionalValue]
   public string? OutMessage
   {
      get {
         VerifyAvailable();
         return _OutMessage_;
      }
   }
   /// <exception cref="InvalidOperationException" />
   [HNotNull]
   public string OutMessageAsError =>
      OutMessage ?? HSPResultErrorMsg.ErrorMessageNotProvided;

   /// <exception cref="InvalidOperationException" />
   [HStrictResult]
   public string _OutMessage =>
      OutMessage ?? throw HSPResultError.OutMessageUnavailable;

   public HSPCommandResultRV() =>
      StateForm = HSPResultStateForm.Invalid;
   /// <exception cref="ArgumentNullException" />
   public HSPCommandResultRV( HSPResultParameters resultParams )
   {
      HArgChecking.VerifyNotNull( 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
//**************************************************************************************************

} // CommonHelpers
