using System;
using System.Reflection;
using Microsoft.AspNetCore.Mvc;

using CommonHelpers;

namespace BookRegistry.Server {

//**************************************************************************************************
[HSyncOnlyDisposable]
class InAction: HDisposable {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
static HConsole CON => HConsole.StdConIO;
//==================================================================================================

/// <exception cref="ArgumentException" />
public InAction(MethodBase controllerTypeMethod)
{
   var type = controllerTypeMethod.DeclaringType.NN();
   if ( !HType.IsTypeOf<ControllerBase>( type ) )
      throw new ArgumentException(
         "Method declaring type is not \"ControllerBase\" or its descentent type.",
         nameof( controllerTypeMethod ) );
   PrintInMethod( type, controllerTypeMethod.ToString().NN() );
   ValidateDisposable();
}
public InAction(ControllerBase controller,string methodNameOrSignature)
{
   PrintInMethod( controller.GetType(), methodNameOrSignature );
   ValidateDisposable();
}

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

protected override void OnDispose(bool synchronous) =>
   CON.FlushPendingNewLine();

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

static void PrintInMethod(Type type,string methodNameOrSignature) =>
   CON.PrintOperation( $"[{type.Name}] {methodNameOrSignature}" );

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // InAction
//**************************************************************************************************

} // BookRegistry.Server
