//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// DataHelpers.SQL satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Data.SqlClient;
using u = user_rtx;

namespace DataHelpers.SQL {

/// <summary>
/// </summary>
[h_db_orm_type]
public partial class HSPOutputReader {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local][u.strict_result][u.opt_result]
public static T GET<T>( SqlParameter parameter, bool treatNullAsDefaultValue=false ) =>
   HSP.GetOutputParameterValue<T>( parameter, treatNullAsDefaultValue );

/// <exception cref="u.EGenericType" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local][u.strict_result][u.opt_result]
public static T VAL<T>( SqlParameter parameter, bool treatNullAsDefaultValue=false )
where T: struct
{
   u.gtype_check.ValueType( typeof(T) );
   return HSP.GetOutputParameterValue<T>( parameter, treatNullAsDefaultValue );
}

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

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local][u.strict_result][u.opt_result]
public static string STR( SqlParameter parameter, bool treatNullAsEmpty=false ) =>
   GET<string?>( parameter, treatNullAsEmpty ) ?? "";
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local][u.strict_result][u.opt_result]
public static string NS( SqlParameter parameter, bool treatNullAsEmpty=false ) =>
   HDbQuery.NormalizeStrValue( GET<string?>( parameter, treatNullAsEmpty ) );

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

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

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local][u.strict_result]
public static double FP( SqlParameter parameter, bool treatNullAsZero=false ) =>
   VAL<double>( parameter, treatNullAsZero );

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local][u.strict_result]
public static decimal DEC( SqlParameter parameter, bool treatNullAsZero=false ) =>
   VAL<decimal>( parameter, treatNullAsZero );

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

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local][u.strict_result]
public static bool BOOL(SqlParameter parameter,bool treatNullAsFalse=false) =>
   VAL<bool>( parameter, treatNullAsFalse );

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

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local][u.strict_result]
public static Guid GUID( SqlParameter parameter, bool treatNullAsEmpty=false ) =>
   VAL<Guid>( parameter, treatNullAsEmpty );

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

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local][u.strict_result]
public static byte[] BINARY( SqlParameter parameter, bool treatNullAsEmpty=false ) =>
   GET<byte[]?>( parameter, treatNullAsEmpty ) ?? Array.Empty<byte>();

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

} // DataHelpers.SQL
