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

namespace DataHelpers.SQL {

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

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local][u.opt_result]
public static T GET<T>( string fieldName, bool treatNullAsDefaultValue=false ) =>
   HDbQuery.GetFieldValue<T>( fieldName, treatNullAsDefaultValue );
/// <exception cref="u.EGenericType" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local][u.opt_result]
public static T VAL<T>( string fieldName, bool treatNullAsDefaultValue=false )
where T: struct
{
   u.gtype_check.ValueType( typeof(T) );
   return HDbQuery.GetFieldValue<T>( fieldName, treatNullAsDefaultValue );
}

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

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local]
public static bool EXISTS( string fieldName ) =>
   HDbQuery.GetFieldIndex( fieldName ) >= 0;
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local][u.strict_result]
public static int IDX( string fieldName ) =>
   HDbQuery.GetFieldIndex( fieldName );

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

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

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

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

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

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

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

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

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

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

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

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

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

} // DataHelpers.SQL
