using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;

using CommonHelpers;

namespace BookRegistry.Server {

//**************************************************************************************************
static class Program {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static readonly string
   AppModuleBaseName = Assembly.GetExecutingAssembly().GetName().Name.NN();

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

/// <exception cref="InvalidOperationException" />
public static bool DevelopmentBehaviour
{
   get {
      int value = _DevelopmentBehaviour_;
      if ( value < 0 )
         throw PropertyNotSpecifiedError();
      return HBool.FromInt( value );
   }
}
/// <exception cref="InvalidOperationException" />
[HAsyncStatic]
public static string ConnectionString =>
   $"Server={StartupData.ServerName};Initial Catalog={StartupData.DatabaseName};"+
   $"Integrated Security=True;Application Name={Program.AppModuleBaseName} (Web-service);"+
   $"Current Language={QueryContext.DBLanguageOrDefault()};"+
   $"MultipleActiveResultSets=False;Pooling=True";

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

public static bool IsDebugConfiguration => BookRegistry_Server_Info.IsDebugConfiguration;
public static bool IsReleaseConfiguration => BookRegistry_Server_Info.IsReleaseConfiguration;

public static string ConfigurationName => BookRegistry_Server_Info.ConfigurationName;

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

internal static void SpecifyDevelopmentBehaviour(bool value) =>
   _DevelopmentBehaviour_ = HBool.ToInt( value );

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

static Program() =>
   HQueryExecContextBase.ConnectionStringAccessor = () => ConnectionString;

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

/// <exception crwf="ArgumentNullException" />
static InvalidOperationException PropertyNotSpecifiedError( [CallerMemberName][HRequired]
                                                            string? propertyName=null ) =>
   HInvOpExceptionCreator.Create(
      "Program property \"{0}\" has not been specified.",
      HArgChecking.NN( propertyName ) );

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

static volatile int _DevelopmentBehaviour_ = -1;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // Program
//**************************************************************************************************

} // BookRegistry.Server
