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

namespace CommonHelpers {

//**************************************************************************************************
[HDbOrmType]
public partial class HSPOutputReader {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HStrictResult][HOptionalResult]
public static T GET<T>(SqlParameter parameter,bool treatNullAsDefaultValue=false) =>
   HSP.GetOutputParameterValue<T>( parameter, treatNullAsDefaultValue );

/// <exception cref="HArgumentTypeException" />
/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HStrictResult][HOptionalResult]
public static T VAL<T>(SqlParameter parameter,bool treatNullAsDefaultValue=false)
where T: struct
{
   HArgChecking.VerifyTypeIsValueType( typeof(T) );
   return HSP.GetOutputParameterValue<T>( parameter, treatNullAsDefaultValue );
}

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

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HStrictResult][HOptionalResult]
public static string STR(SqlParameter parameter,bool treatNullAsEmpty=false) =>
   GET<string?>( parameter, treatNullAsEmpty ) ?? "";
/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HStrictResult][HOptionalResult]
public static string NS(SqlParameter parameter,bool treatNullAsEmpty=false) =>
   HDbQuery.NormalizeStrValue( GET<string?>( parameter, treatNullAsEmpty ) );

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

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HStrictResult]
public static int INT(SqlParameter parameter,bool treatNullAsZero=false) =>
   VAL<int>( parameter, treatNullAsZero );
/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HStrictResult]
public static long BIGINT(SqlParameter parameter,bool treatNullAsZero=false) =>
   VAL<long>( parameter, treatNullAsZero );

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HStrictResult]
public static double FP(SqlParameter parameter,bool treatNullAsZero=false) =>
   VAL<double>( parameter, treatNullAsZero );

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HStrictResult]
public static decimal DEC(SqlParameter parameter,bool treatNullAsZero=false) =>
   VAL<decimal>( parameter, treatNullAsZero );

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

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HStrictResult]
public static bool BOOL(SqlParameter parameter,bool treatNullAsFalse=false) =>
   VAL<bool>( parameter, treatNullAsFalse );

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HStrictResult]
public static DateTime DT(SqlParameter parameter) =>
   VAL<DateTime>( parameter );
/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HStrictResult]
public static DateTime UTC(SqlParameter parameter) =>
   VAL<DateTime>( parameter ).ToUniversalTime();

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HStrictResult]
public static Guid GUID(SqlParameter parameter,bool treatNullAsEmpty=false) =>
   VAL<Guid>( parameter, treatNullAsEmpty );

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

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HStrictResult]
public static byte[] BINARY(SqlParameter parameter,bool treatNullAsEmpty=false) =>
   GET<byte[]?>( parameter, treatNullAsEmpty ) ?? new byte[0];

//--------------------------------------------------------------------------------------------------
/*
/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HStrictResult]
public static ... ...(SqlParameter parameter,bool treatNullAs...=false) =>
   VAL<>( parameter, treatNullAs...=false );
   GET<>( parameter, treatNullAs...=false );
*/
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HSPOutputReader
//**************************************************************************************************

} // CommonHelpers
