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

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

//**************************************************************************************************
/// <summary>
/// </summary>
partial class HWin32Error {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[CLSCompliant(false)]
public static HOperationFailedException CreateOpFailedException(uint errorCode)
{
   return CreateOpFailedException( unchecked( (int)errorCode ) );
}

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

public static HOperationFailedException CreateOpFailedException(int errorCode)
{
   return new HOperationFailedException( ErrorCodeToMessage( errorCode ) );
}

/// <exception cref="ArgumentNullException" />
public static HOperationFailedException CreateOpFailedException(Win32Exception error)
{
   HArgChecking.VerifyNotNull( error );
   return CreateOpFailedException( NormalizeErrorMessage( error.Message ) );
}

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

public static HOperationFailedException CreateOpFailedExceptionFromLastError()
{
   return CreateOpFailedException( LastErrorCode );
}

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

/// <exception cref="ArgumentNullException" />
public static HOperationFailedException CreateOpFailedException(string functionName)
{
   return CreateOpFailedException( functionName, null );
}

/// <exception cref="ArgumentNullException" />
public static HOperationFailedException CreateOpFailedException
(
   string functionName, [HOptional] string remarkMessage
)
{
   HArgChecking.VerifyNotNull( functionName );
   return HOpFailedExceptionCreator.Create(
      ComposeOpFailedErrorMessage( functionName, remarkMessage ) );
}

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

/// <exception cref="ArgumentNullException" />
public static HOperationFailedException CreateOpFailedExceptionWithResultCodeToken
(
   string functionName, string resultCodeToken
)
{
   HArgChecking.VerifyNotNulls( functionName, resultCodeToken );
   return CreateOpFailedException(
      ComposeOpFailedErrorMessageWithResultCodeToken( functionName, resultCodeToken ) );
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HWin32Error
//**************************************************************************************************

} // CommonHelpers (.WASM)
#endif // WIN32
