using System.ComponentModel.DataAnnotations;
using Asp.Versioning;
using Baya.Application.Features.Audit.Queries.GetAuditTrail;
using Baya.Application.Models.Audit;
using Baya.Application.Models.Common;
using Baya.Infrastructure.Identity.Identity.PermissionManager;
using Baya.WebFramework.Attributes;
using Baya.WebFramework.BaseController;
using Mediator;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Baya.Web.Api.Controllers.V1;

[ApiVersion("1")]
[ApiController]
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize(ConstantPolicies.DynamicPermission)]
[Display(Description = "Admin: the immutable, append-only audit trail")]
public sealed class AuditController(ISender sender) : BaseController
{
    [HttpGet("[action]")]
    [ProducesOkApiResponseType<PagedResult<AuditLogDto>>]
    public async Task<IActionResult> GetAuditTrail([FromQuery] GetAuditTrailQuery query, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(query, cancellationToken));
}
