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

#if !WASM
namespace CommonHelpers {
#else
namespace CommonHelpers.WASM {
#endif

//**************************************************************************************************
/// <summary>
/// </summary>
public static partial class HArgChecking {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static ArgumentException ArgumentException_IncorrectArguments
{
   get { return new ArgumentException( "Incorrect argument(s)." ); }
}

//--------------------------------------------------------------------------------------------------

public static ArgumentException ArgumentException_DefaultValue =>
   new ArgumentException( "Value must not be equal to default value of its type." );

//--------------------------------------------------------------------------------------------------

public static ArgumentException ArgumentException_ZeroPointer
{
   get { return new ArgumentException( "Pointer is zero." ); }
}

public static ArgumentException ArgumentException_InvalidPointer
{
   get { return new ArgumentException( "Invalid pointer value." ); }
}

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

/// <exception cref="ArgumentNullException" />
public static void VerifyNotNull(object value)
{
   if ( value == null )
      throw new ArgumentNullException();
}
/// <exception cref="ArgumentNullException" />
public static T VerifyNotNull<T>(T value)
{
   if ( value == null )
      throw new ArgumentNullException();
   return value;
}

/// <exception cref="ArgumentNullException" />
public static object[] VerifyNotNulls(params object[] values)
{
   if ( !HOps.CheckNotNulls( values ) )
      throw new ArgumentNullException();
   return values;
}

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

/// <exception cref="ArgumentException" />
public static T VerifyNotDefalutValue<T>(T value) where T: struct,IComparable<T>
{
   if (value.CompareTo(default(T))==0)
      throw ArgumentException_DefaultValue;
   return value;
}

//--------------------------------------------------------------------------------------------------

/// <exception cref="ArgumentException" />
public static IntPtr VerifyNotZeroPointer(IntPtr pointer)
{
   if ( pointer == IntPtr.Zero )
      throw ArgumentException_ZeroPointer;
   return pointer;
}
/// <exception cref="ArgumentException" />
[CLSCompliant(false)]
public static UIntPtr VerifyNotZeroPointer(UIntPtr pointer)
{
   if ( pointer == UIntPtr.Zero )
      throw ArgumentException_ZeroPointer;
   return pointer;
}

/// <exception cref="ArgumentException" />
/// <exception cref="ArgumentNullException" />
public static IntPtr[] VerifyNotZeroPointers(params IntPtr[] pointers)
{
   if ( !HOps.CheckNotNulls( pointers ) )
      throw new ArgumentNullException();
   return pointers;
}
/// <exception cref="ArgumentException" />
/// <exception cref="ArgumentNullException" />
[CLSCompliant(false)]
public static UIntPtr[] VerifyNotZeroPointers(params UIntPtr[] pointers)
{
   if ( !HOps.CheckNotNulls( pointers ) )
      throw new ArgumentNullException();
   return pointers;
}

//--------------------------------------------------------------------------------------------------

/// <exception cref="ArgumentException" />
public static IntPtr VerifyNotInvalidPointer(IntPtr pointer)
{
   if ( pointer == HIntPtr.MinusOneValue )
      throw ArgumentException_InvalidPointer;
   return pointer;
}

//--------------------------------------------------------------------------------------------------

/// <exception cref="ArgumentOutOfRangeException" />
public static T VerifyBetween<T>(T value,T lowerBound,T upperBound) where T: IComparable<T>
{
   if ( !HOps.IsBetween( value, lowerBound, upperBound ) )
      throw new ArgumentOutOfRangeException();
   return value;
}

/// <exception cref="ArgumentOutOfRangeException" />
public static T VerifyExBetween<T>(T value,T lowerBound,T upperBound) where T: IComparable<T>
{
   if ( !HOps.IsExBetween( value, lowerBound, upperBound ) )
      throw new ArgumentOutOfRangeException();
   return value;
}

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

static HArgChecking()
{
   CommonHelpers_Core.Access();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HArgChecking
//**************************************************************************************************

} // CommonHelpers (.WASM)
