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

namespace CommonHelpers {

//**************************************************************************************************
partial class HResultSetReader {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HOptionalResult]
public static T? VAL_N<T>(string fieldName) where T: struct =>
   HDbQuery.GetFieldValue<T?>( fieldName );

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

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HOptionalResult]
public static string? STR_N(string fieldName) =>
   GET<string?>( fieldName, true );
/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HOptionalResult]
public static string? NS_N(string fieldName)
{
   string? str = GET<string?>( fieldName, true );
   return str!=null ? HDbQuery.NormalizeStrValue( str ) : null;
}

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

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic]
public static int? INT_N(string fieldName) =>
   VAL_N<int>( fieldName );
/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic]
public static long? BIGINT_N(string fieldName) =>
   VAL_N<long>( fieldName );

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic]
public static double? FP_N(string fieldName) =>
   VAL_N<double>( fieldName );

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic]
public static decimal? DEC_N(string fieldName) =>
   VAL_N<decimal>( fieldName );

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

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic]
public static bool? BOOL_N(string fieldName) =>
   VAL_N<bool>( fieldName );

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic]
public static DateTime? DT_N(string fieldName) =>
   VAL_N<DateTime>( fieldName );
/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic]
public static DateTime? UTC_N(string fieldName)
{
   var dt = VAL_N<DateTime>( fieldName );
   return dt.HasValue ? (DateTime?)dt.Value.ToUniversalTime() : null;
}

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic]
public static Guid? GUID_N(string fieldName) =>
   VAL_N<Guid>( fieldName );

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

/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic][HOptionalResult]
public static byte[]? BINARY_N(string fieldName) =>
   GET<byte[]?>( fieldName, true );

//--------------------------------------------------------------------------------------------------
/*
/// <exception cref="ArgumentNullException" />
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[HAsyncStatic]
public static ...? ..._N(string fieldName) =>
   VAL_N<...>( fieldName );
   GET<...?>( fieldName );
*/
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HResultSetReader
//**************************************************************************************************

} // CommonHelpers
