using Fitness_core_BE.Helpers;
using Fitness_core_BE.Models.IOs;
using Fitness_core_BE.Services.FunctionHandler;
using Fitness_core_BE.Services.Document;
using Fitness_core_BE.Interfaces.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using System.Text.Json;
using static Fitness_core_BE.Helpers.JwtMiddleware;
using Fitness_core_BE.DTOs;
namespace Fitness_core_BE.Controllers
{
///
/// Main API Controller for handling various operations
///
[Route("api")]
[ApiController]
[Produces("application/json")]
[EnableCors("AllowAll")]
public class APIController : ControllerBase
{
private readonly TicketFuncHandler _ticketFuncHandler;
private readonly ActivityLogFuncHandler _activityLogFuncHandler;
private readonly ClientFuncHandler _clientFuncHandler;
private readonly StaffFunctionHandler _staffFuncHandler;
private readonly ClientInvoiceFunctionHandler _clientInvoiceFuncHandler;
private readonly CustomerFunctionHandler _customerFuncHandler;
private readonly CustomerInvoiceFunctionHandler _customerInvoiceFuncHandler;
private readonly CustomerPlanFunctionHandler _customerPlanFuncHandler;
private readonly CustomerSubscriptionFunctionHandler _customerSubscriptionFuncHandler;
private readonly MealFunctionHandler _mealFuncHandler;
private readonly AuthFuncHandler _authFuncHandler;
private readonly WorkoutFunctionHandler _workoutFuncHandler;
private readonly DocumentFunctionHandler _documentFuncHandler;
private readonly ChatFunctionHandler _chatFuncHandler;
private readonly FeedFuncHandler _feedFuncHandler;
private readonly AccessDeviceFunctionHandler _accessDeviceFuncHandler;
private readonly AttendanceFunctionHandler _attendanceFuncHandler;
private readonly DocumentFunctionHandler _docHandler;
private readonly IDocumentService _docService;
private readonly UserRegisterHandler _userRegisterHandler;
private readonly ClientStatFuncHandler _clientStatFuncHandler;
private readonly PaymentFunctionHandler _paymentFuncHandler;
public APIController(
TicketFuncHandler ticketFuncHandler,
ActivityLogFuncHandler activityLogFuncHandler,
ClientFuncHandler clientFuncHandler,
AuthFuncHandler authFuncHandler,
StaffFunctionHandler staffFuncHandler,
ClientInvoiceFunctionHandler clientInvoiceFuncHandler,
CustomerFunctionHandler customerFuncHandler,
CustomerInvoiceFunctionHandler customerInvoiceFuncHandler,
CustomerPlanFunctionHandler customerPlanFuncHandler,
CustomerSubscriptionFunctionHandler customerSubscriptionFuncHandler,
MealFunctionHandler mealFuncHandler,
WorkoutFunctionHandler workoutFuncHandler,
DocumentFunctionHandler documentFuncHandler,
FeedFuncHandler feedFuncHandler,
AccessDeviceFunctionHandler accessDeviceFuncHandler,
AttendanceFunctionHandler attendanceFuncHandler,
ChatFunctionHandler chatFunctionHandler,
DocumentFunctionHandler docHandler,
IDocumentService docService,
UserRegisterHandler userRegisterHandler,
ClientStatFuncHandler clientStatFuncHandler,
PaymentFunctionHandler paymentFuncHandler)
{
_ticketFuncHandler = ticketFuncHandler;
_activityLogFuncHandler = activityLogFuncHandler;
_clientFuncHandler = clientFuncHandler;
_staffFuncHandler = staffFuncHandler;
_clientInvoiceFuncHandler = clientInvoiceFuncHandler;
_customerFuncHandler = customerFuncHandler;
_customerInvoiceFuncHandler = customerInvoiceFuncHandler;
_customerPlanFuncHandler = customerPlanFuncHandler;
_customerSubscriptionFuncHandler = customerSubscriptionFuncHandler;
_mealFuncHandler = mealFuncHandler;
_authFuncHandler = authFuncHandler;
_workoutFuncHandler = workoutFuncHandler;
_documentFuncHandler = documentFuncHandler;
_feedFuncHandler = feedFuncHandler;
_accessDeviceFuncHandler = accessDeviceFuncHandler;
_attendanceFuncHandler = attendanceFuncHandler;
_chatFuncHandler = chatFunctionHandler;
_docHandler = docHandler;
_docService = docService;
_userRegisterHandler = userRegisterHandler;
_clientStatFuncHandler = clientStatFuncHandler;
_paymentFuncHandler = paymentFuncHandler;
}
///
/// Check API health status
///
/// API status and current timestamp
/// Returns API status
[HttpGet("status")]
[CustomMiddleware]
[TenantResolution]
[ProducesResponseType(StatusCodes.Status200OK)]
public IActionResult GetStatus()
{
return Ok(new { status = "API is running", timestamp = System.DateTime.UtcNow });
}
[HttpPost("ticket")]
[CustomMiddleware]
[TenantResolution]
public async Task ExecuteTicket([FromBody] ApiRequest request)
{
var response = await _ticketFuncHandler.Execute(request, HttpContext);
return StatusCode(response.StatusCode, response);
}
[HttpPost("activitylog")]
public async Task ExecuteActivityLog([FromBody] ApiRequest request)
{
var response = await _activityLogFuncHandler.ExecuteAsync(request.FunctionName, request.Payload, HttpContext);
return Ok(new ApiResponse