using adas_core.Authentication.Attributes;
using adas_core.Domain.Enums;
using adas_core.Infrastructure.Services;
using adas_core.Logging;
using Microsoft.AspNetCore.Mvc;

namespace adas_core.Controllers;

[Route("rabbit")]
[ApiController]
public class RabbitController(ReceiverService receiverService) : ControllerBase
{
    [HttpPost]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthAdmin)]
    [Route("start-consume/{queueName}")]
    public async Task<IActionResult> ConsumeErrorQueue(string queueName)
    {
        LogExecutionContext.TrySetTraceIdentifier(Guid.NewGuid().ToString(), true);

        await receiverService.ProcessErrorQueue(queueName);
        return Ok();
    }

    [HttpPost]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthAdmin)]
    [Route("stop-consume/{queueName}")]
    public async Task<IActionResult> ConsumeStopErrorQueue(string queueName)
    {
        LogExecutionContext.TrySetTraceIdentifier(Guid.NewGuid().ToString(), true);
        await receiverService.ProcessErrorQueue(queueName);
        return Ok();
    }
}