using e_suite.API.Common;
using e_suite.Utilities.Pagination;
using eSuite.API.security;
using eSuite.API.Utilities;
using eSuite.Core.Security;
using Microsoft.AspNetCore.Mvc;

namespace eSuite.API.Controllers;

/// <summary>
/// Methods used for viewing the audit trail
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class AuditController : ESuiteControllerBase
{
    private readonly IAuditLog _auditLog;

    /// <summary>
    /// Constructor for the Audit Controller.
    /// </summary>
    /// <param name="auditLog"></param>
    public AuditController(IAuditLog auditLog)
    {
        _auditLog = auditLog;
    }

    /// <summary>
    /// Returns the audit entries for the system
    /// </summary>
    /// <remarks>Returns all audit log entries</remarks>
    [Route("log")]
    [HttpGet]
    [AccessKey(SecurityAccess.ViewAuditLog)]
    [ProducesResponseType(StatusCodes.Status200OK)]
    public async Task<IActionResult> Get([FromQuery] Paging paging, [FromQuery] string? logEntry, [FromQuery] bool primaryOnly, CancellationToken cancellationToken = default!)
    {
        var result = await _auditLog.GetAuditLogEntries(paging, logEntry, primaryOnly, cancellationToken);
        return Ok(result);
    }
}