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

namespace CommonHelpers {

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

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HOptionalResult]
public static T GET<T>(string fieldName,bool treatNullAsDefaultValue=false) =>
   HDbQuery.GetFieldValue<T>( fieldName, treatNullAsDefaultValue );
/// <exception cref="HArgumentTypeException" />
/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HOptionalResult]
public static T VAL<T>(string fieldName,bool treatNullAsDefaultValue=false)
where T: struct
{
   HArgChecking.VerifyTypeIsValueType( typeof(T) );
   return HDbQuery.GetFieldValue<T>( fieldName, treatNullAsDefaultValue );
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

} // CommonHelpers
