using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;

using CommonHelpers;
using BookRegistry.Server.DB;

namespace BookRegistry.Server {

//**************************************************************************************************
partial class WeatherForecastController {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[HttpPost("[action]")][AllowAnonymous]
public Task<dynamic> GetForecast( GetWeatherForecast_Args args ) =>
Do_A(args,async()=>{ // WeatherForecast_Response
//-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   var dateFrom = args.DateFrom;

   CON.Print( "Query language: {0}", args.query_Language );
   CON.Print( Program.ConnectionString );

   if ( args.WithTestDelay )
   {
      const int delayInterval = 3000;
      CON.PrintOperation( "Performing test delay: {0} ms", delayInterval );
      await Task.Delay( delayInterval );
   }

   CON.PrintOperation(
      "Retreiving week forcast for: {0} (start date)",
      dateFrom.ToShortDateString() );
   var ( spr, message ) = await GetWeatherForecastSummaries_SP.EXEC_A(
      dateFrom, args.SimulateError );
   if ( message != null )
      CON.PrintExpressive( message );
   if ( !spr.Success )
      return new GeneralApiResponse<ForecastSummary_Item>( spr );
// return GeneralApiResponse.GENERAL_FAILURE;
// return new GeneralApiResponse( "Weather forecast is unavailable." );
   return new WeatherForecast_Response( spr, spr.List );
//-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
});

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // WeatherForecastController
//**************************************************************************************************

} // BookRegistry.Server
