using System.ComponentModel.DataAnnotations;
using Asp.Versioning;
using Baya.Application.Features.Verification.Commands.DeactivateStepType;
using Baya.Application.Features.Verification.Commands.UpsertStepType;
using Baya.Application.Features.Verification.Queries.ListStepTypes;
using Baya.Application.Models.Verification;
using Baya.Infrastructure.Identity.Identity.PermissionManager;
using Baya.WebFramework.Attributes;
using Baya.WebFramework.BaseController;
using Mediator;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting;
using Baya.WebFramework.ServiceConfiguration;

namespace Baya.Web.Api.Controllers.V1;

[ApiVersion("1")]
[ApiController]
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize(ConstantPolicies.DynamicPermission)]
[EnableRateLimiting(RateLimitingServiceExtension.SensitivePolicy)]
[Display(Description = "Admin catalog of verification step-types (the data-driven pipeline)")]
public sealed class AdminVerificationStepTypesController(ISender sender) : BaseController
{
    [HttpGet]
    [ProducesOkApiResponseType<IReadOnlyList<VerificationStepTypeDto>>]
    public async Task<IActionResult> List([FromQuery] bool includeInactive, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(new AdminListStepTypesQuery(includeInactive), cancellationToken));

    [HttpPost]
    [ProducesOkApiResponseType<VerificationStepTypeDto>]
    public async Task<IActionResult> Upsert(AdminUpsertStepTypeCommand command, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(command, cancellationToken));

    [HttpDelete("{id}")]
    [ProducesOkApiResponseType]
    public async Task<IActionResult> Deactivate(long id, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(new AdminDeactivateStepTypeCommand(id), cancellationToken));
}
