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

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

partial class XmlConfigurationBase {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="InvalidOperationException" />
protected string ProvideErrorMessageWithFile( string message ) =>
   ComposeErrorMessageWithFile( FileFullPath, message );

/// <exception cref="InvalidOperationException" />
protected string ProvideErrorMessageWithFile( string messageFmt, params object?[] args ) =>
   ProvideErrorMessageWithFile( string.Format( messageFmt, args ) );

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

/// <exception cref="InvalidOperationException" />
protected string ProvideErrorMessageWithPath( string message ) =>
   ComposeErrorMessageWithPath( FileFullPath, CurrentElementPath, message );

/// <exception cref="InvalidOperationException" />
protected string ProvideErrorMessageWithPath( string messageFmt, params object?[] args ) =>
   ProvideErrorMessageWithPath( string.Format( messageFmt, args ) );

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

/// <exception cref="InvalidOperationException" />
protected string ProvideErrorMessageWithPathAndAttribute( string attributeName, string message ) =>
   ComposeErrorMessageWithPathAndAttribute(
      FileFullPath, CurrentElementPath, attributeName, message );

/// <exception cref="InvalidOperationException" />
protected string ProvideErrorMessageWithPathAndAttribute( string attributeName,
                                                          string messageFmt,
                                                          params object?[] args ) =>
   ProvideErrorMessageWithPathAndAttribute(
      attributeName, string.Format( messageFmt, args ) );

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

/// <exception cref="InvalidOperationException" />
protected string ProvideErrorMessageWithExplicitPath( string elementPath, string message ) =>
   ComposeErrorMessageWithPath( FileFullPath, elementPath, message );

/// <exception cref="InvalidOperationException" />
protected string ProvideErrorMessageWithExplicitPath( string elementPath,
                                                      string messageFmt,
                                                      params object?[] args ) =>
   ProvideErrorMessageWithExplicitPath( elementPath, string.Format( messageFmt, args ) );

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

/// <exception cref="InvalidOperationException" />
protected string ProvideErrorMessageWithExplicitPathAndAttribute( string elementPath,
                                                                  string attributeName,
                                                                  string message ) =>
   ComposeErrorMessageWithPathAndAttribute(
      FileFullPath, elementPath, attributeName, message );

/// <exception cref="InvalidOperationException" />
protected string ProvideErrorMessageWithExplicitPathAndAttribute( string elementPath,
                                                                  string attributeName,
                                                                  string messageFmt,
                                                                  params object?[] args ) =>
   ProvideErrorMessageWithExplicitPathAndAttribute(
      elementPath, attributeName, string.Format( messageFmt, args ) );

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

protected static string ComposeErrorMessageWithFile( string? filePath, string message ) =>
   filePath != null ?
      u.str.FMT(
         "{0}\n"+
         u.local.T(RC.File,"Файл")+": “{1}”.",
         message, filePath ) :
      message;

protected static string ComposeErrorMessageWithFile( string? filePath,
                                                     string messageFmt,
                                                     params object?[] args ) =>
   ComposeErrorMessageWithFile( filePath, string.Format( messageFmt, args ) );

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

protected static string ComposeErrorMessageWithPath( string? filePath,
                                                     string elementPath,
                                                     string message ) =>
   ComposeErrorMessageWithFile( filePath, string.Format(
      "{0}\n"+
      u.local.T(RC.ElementPath,"Путь к элементу")+": “{1}”.",
      message, elementPath ));

protected static string ComposeErrorMessageWithPath( string? filePath,
                                                     string elementPath,
                                                     string messageFmt,
                                                     params object?[] args ) =>
   ComposeErrorMessageWithPath(
      filePath, elementPath, string.Format(messageFmt,args) );

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

protected string ComposeErrorMessageWithPathAndAttribute( string? filePath,
                                                          string elementPath,
                                                          string attributeName,
                                                          string message )
{
   VerifyCurrentElementSelected();
   return ComposeErrorMessageWithPath( filePath, elementPath, string.Format(
      "{0}\n"+
      u.local.T(RC.Attribute,"Атрибут")+": “{1}”.",
      message, attributeName ));
}

protected string ComposeErrorMessageWithPathAndAttribute( string? filePath,
                                                          string elementPath,
                                                          string attributeName,
                                                          string messageFmt,
                                                          params object?[] args ) =>
   ComposeErrorMessageWithPathAndAttribute(
      filePath, elementPath, attributeName, string.Format( messageFmt, args ) );

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // XmlConfigurationBase

} // user_rtx (.wasm)
