//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// UserRTX.NET satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Collections.Generic;

#if !WASM
namespace user_rtx { using u = user_rtx;
#else
namespace user_rtx.wasm { using u = user_rtx.wasm;
#endif

/// <summary>
/// Predifined sound identifiers (names)
/// </summary>
public static class sound_ids {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public const string
   None        = "none",
   Default     = "default",
   Success     = "success",
   NotSuccess  = "not_success",
   Information = "information",
   Error       = "error",
   Failure     = "failure",
   Warning     = "warning",
   Exclamation = "exclamation",
   Question    = "question",
   Confirmation= "confirmation",
   Attention   = "attention",
   Disabled    = "disabled";

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

public static object SyncRoot { get; } = new object();

public static Dictionary<string,object?>
   DictionaryUnsafe => _dictionary;

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

public static bool IsNoneId( string soundId ) =>
   u.str.IsOneOf( true, soundId, "", None );

public static bool IsDefaultId( string soundId ) =>
   u.str.IsOneOf( true, soundId, Default );

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

public static bool IsRegisteredId( string soundId )
{
   lock ( SyncRoot ) {
      object? playbackInfo;
      return _dictionary.TryGetValue( soundId, out playbackInfo );
   }
}

[u.needs_in_lock]
public static void RegisterBeeps_NoLock( string soundId, u.NamedBeepArray layout ) =>
   _dictionary[ soundId ] = layout;

[u.needs_in_lock]
public static void RegisterAny_NoLock( string soundId, object? playbackInfo ) =>
   _dictionary[ soundId ] = playbackInfo;

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

[u.thread_safe]
public static object? GetPlayback( string soundId )
{
   lock ( SyncRoot )
      return _dictionary[ soundId ];
}

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

static sound_ids()
{
   RegisterAny_NoLock( "", null );
   RegisterAny_NoLock( None, null );
   RegisterAny_NoLock( Default, null );
   RegisterBeeps_NoLock( Success       , ( Success       , new u.BeepNote[]{ (1, 1), (2, 1) } ));
   RegisterBeeps_NoLock( NotSuccess    , ( NotSuccess    , new u.BeepNote[]{ (0.5, 3) } ));
   RegisterBeeps_NoLock( Information   , ( Information   , new u.BeepNote[]{ (1, 1) } ));
   RegisterBeeps_NoLock( Error         , ( Error         , new u.BeepNote[]{ (2, 2) } ));
   RegisterBeeps_NoLock( Failure       , ( Failure       , new u.BeepNote[]{ (2, 2) } ));
   RegisterBeeps_NoLock( Warning       , ( Warning       , new u.BeepNote[]{ (1, 1) } ));
   RegisterBeeps_NoLock( Exclamation   , ( Exclamation   , new u.BeepNote[]{ (1, 1) } ));
   RegisterBeeps_NoLock( Question      , ( Question      , new u.BeepNote[]{ (1, 1) } ));
   RegisterBeeps_NoLock( Confirmation  , ( Confirmation  , new u.BeepNote[]{ (1, 1) } ));
   RegisterBeeps_NoLock( Attention     , ( Attention     , new u.BeepNote[]{ (1, 1) } ));
   RegisterBeeps_NoLock( Disabled      , ( Disabled      , new u.BeepNote[]{ (2, 1) } ));
}

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

static readonly Dictionary<string,object?>
   _dictionary = new ( StringComparer.OrdinalIgnoreCase );

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // sound_ids

} // user_rtx (.wasm)
