using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ROLAC.API.Authorization;
using ROLAC.API.DTOs.Logging;
using ROLAC.API.Entities.Logging;
using ROLAC.API.Services.Logging;

namespace ROLAC.API.Controllers;

[ApiController]
[Route("api/system-logs")]
[Authorize]
public class SystemLogsController : ControllerBase
{
    private readonly ISystemLogQueryService _svc;
    public SystemLogsController(ISystemLogQueryService svc) => _svc = svc;

    [HttpGet]
    [HasPermission(Modules.SystemLogs, PermissionActions.Read)]
    public async Task<IActionResult> GetPaged([FromQuery] SystemLogQuery query)
        => Ok(await _svc.GetPagedAsync(query));

    [HttpGet("{id:long}")]
    [HasPermission(Modules.SystemLogs, PermissionActions.Read)]
    public async Task<IActionResult> GetById(long id)
    {
        var dto = await _svc.GetByIdAsync(id);
        return dto is null ? NotFound() : Ok(dto);
    }

    /// <summary>All six severities, so the UI can offer every filter option regardless of data.</summary>
    [HttpGet("levels")]
    [HasPermission(Modules.SystemLogs, PermissionActions.Read)]
    public IActionResult GetLevels() => Ok(Enum.GetNames<LogLevelEnum>());
}
