//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// 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>
/// Argument checking for array
/// </summary>
public static partial class array_argcheck {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <summary>
/// Zero-based-array checking for single rank array
/// </summary>
/// <exception cref="ArgumentException" />
[u.returns_source]
public static T[] ZeroBased<T>( T[] array, string paramName ) =>
   array.GetLowerBound( 0 ) == 0 ? array :
      throw u.array_argcheck_errors.ZERO_BASED_ARRAY_WAS_EXPECTED( paramName );

/// <summary>
/// Zero-based-array checking for single rank array
/// </summary>
/// <exception cref="ArgumentException" />
[u.returns_source]
public static Array ZeroBased( Array array, string paramName ) =>
   Rank1Array( array, nameof(paramName) ).GetLowerBound( 0 ) == 0 ? array :
      throw u.array_argcheck_errors.ZERO_BASED_ARRAY_WAS_EXPECTED( paramName );

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

/// <summary>
/// Single-rank-array checking
/// </summary>
/// <exception cref="ArgumentException" />
[u.returns_source]
public static Array Rank1Array( Array array, string paramName ) =>
   array.Rank == 1 ? array :
      throw u.array_argcheck_errors.SINGLE_DIMENSION_ARRAY_WAS_EXPECTED( paramName );

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

/// <summary>
/// Not-empty-array checking for single rank array
/// </summary>
/// <exception cref="ArgumentException" />
[u.returns_source]
public static T[] NotEmpty<T>( T[] array, string paramName ) =>
   array.Length > 0 ? array :
      throw u.array_argcheck_errors.NONEMPTY_ARRAY_WAS_EXPECTED( paramName );

/// <summary>
/// Not-empty-array checking for single rank array
/// </summary>
/// <exception cref="ArgumentException" />
[u.returns_source]
public static Array NotEmpty<T>( Array array, string paramName ) =>
   Rank1Array( array, nameof(paramName) ).GetLength( 0 ) > 0 ? array :
      throw u.array_argcheck_errors.NONEMPTY_ARRAY_WAS_EXPECTED( paramName );

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // array_argcheck

} // user_rtx (.wasm)
