//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// UserRTX.NET satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;

#if !WASM
namespace user_rtx { using u = user_rtx;
#else
namespace user_rtx.wasm { using u = user_rtx.wasm;
#endif

/// <summary>
/// Helpers for “System.Boolean” value type
/// </summary>
public static class boolean {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static int ToInt( bool value ) =>
   value ? 1 : 0;

/// <exception cref="ArgumentOutOfRangeException" />
public static bool FromInt( int value, bool throwOnIncorrect=true )
{
   switch ( value )
   {
   case 0: return false;
   case 1: return true;
   default:
      if ( throwOnIncorrect )
         throw e_argument_outofrange.NewWith( nameof(value),
            "Incorrect integer value to represent it as boolean. "+
            "The only admissible values are 1 or 0." );
      return true;
   } // switch
}

//==================================================================================================

public static string OneZeroFlag( bool value ) =>
   value ? "1" : "0";
public static string OneZeroFlagOrEmpty( bool? value ) =>
   value.HasValue ? OneZeroFlag( value.Value ) : "";

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // boolean

} // user_rtx (.wasm)
