using System;
using System.Runtime.CompilerServices;
using Microsoft.AspNetCore.Mvc;

using CommonHelpers;

namespace BookRegistry.Server {

//**************************************************************************************************
partial class GeneralApiResponseController {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="InvalidOperationException" />
[HAsyncStatic]
protected dynamic Do<TItem>( ApiArgumentsBase? args,
                             Func<GeneralApiResponse<TItem>> body,
                             [CallerMemberName][HRequired] string? methodNameOrSignature=null )
{
   ApplyQueryArgsToContext( args );
   return DoAuto<GeneralApiResponse<TItem>>(
      CreateErrorResponseWithItemsCallback<TItem>(), body, methodNameOrSignature );
}

/// <exception cref="InvalidOperationException" />
[HAsyncStatic]
protected dynamic DoDynamic<TItem>( ApiArgumentsBase? args,
                                    Func<dynamic> body,
                                    [CallerMemberName][HRequired]
                                    string? methodNameOrSignature=null )
{
   ApplyQueryArgsToContext( args );
   return base.DoDynamic<dynamic>( CreateErrorResponseWithItemsCallback<TItem>(), body,
                                   methodNameOrSignature );
}

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

/// <exception cref="InvalidOperationException" />
[HAsyncStatic]
protected ActionResult<GeneralApiResponse<TItem>> DoExplicit<TItem>(
   ApiArgumentsBase? args,
   Func<ActionResult<GeneralApiResponse<TItem>>> body,
   [CallerMemberName][HRequired] string? methodNameOrSignature=null )
{
   ApplyQueryArgsToContext( args );
   return base.DoExplicit<GeneralApiResponse<TItem>>(
      CreateErrorResponseWithItemsCallback<TItem>(), body, methodNameOrSignature );
}

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

/// <exception cref="InvalidOperationException" />
[HAsyncStatic]
protected dynamic Do<TItem>( string methodNameOrSignature,
                             ApiArgumentsBase? args, Func<GeneralApiResponse<TItem>> body )
{
   ApplyQueryArgsToContext( args );
   return DoAuto<GeneralApiResponse<TItem>>(
      methodNameOrSignature, CreateErrorResponseWithItemsCallback<TItem>(), body );
}

/// <exception cref="InvalidOperationException" />
[HAsyncStatic]
protected dynamic DoDynamic<TItem>( string methodNameOrSignature,
                                    ApiArgumentsBase? args, Func<dynamic> body )
{
   ApplyQueryArgsToContext( args );
   return base.DoDynamic<dynamic>(
      methodNameOrSignature, CreateErrorResponseWithItemsCallback<TItem>(), body );
}

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

/// <exception cref="InvalidOperationException" />
[HAsyncStatic]
protected ActionResult<GeneralApiResponse<TItem>> DoExplicit<TItem>(
   string methodNameOrSignature,
   ApiArgumentsBase? args,
   Func<ActionResult<GeneralApiResponse<TItem>>> body )
{
   ApplyQueryArgsToContext( args );
   return base.DoExplicit<GeneralApiResponse<TItem>>(
      methodNameOrSignature, CreateErrorResponseWithItemsCallback<TItem>(), body );
}

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

static Func<string,GeneralApiResponse<TItem>> CreateErrorResponseWithItemsCallback<TItem>() =>
   GeneralApiResponse<TItem>.CreateServerError;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // GeneralApiResponseController
//**************************************************************************************************

} // BookRegistry.Server
