using System.ComponentModel.DataAnnotations;
using Asp.Versioning;
using Baya.Application.Features.SupportAlerts.Commands.AssignSupportAlert;
using Baya.Application.Features.SupportAlerts.Commands.ResolveSupportAlert;
using Baya.Application.Features.SupportAlerts.Queries.ListSupportAlerts;
using Baya.Application.Models.Common;
using Baya.Application.Models.SupportAlerts;
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-only: the internal support-alert worklist (never user-facing)")]
public sealed class SupportAlertsController(ISender sender) : BaseController
{
    [HttpGet("[action]")]
    [ProducesOkApiResponseType<PagedResult<SupportAlertDto>>]
    public async Task<IActionResult> GetSupportAlerts([FromQuery] ListSupportAlertsQuery query, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(query, cancellationToken));

    [HttpPost("[action]")]
    [ProducesOkApiResponseType]
    public async Task<IActionResult> AssignSupportAlert(AssignSupportAlertCommand command, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(command, cancellationToken));

    [HttpPost("[action]")]
    [ProducesOkApiResponseType]
    public async Task<IActionResult> ResolveSupportAlert(ResolveSupportAlertCommand command, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(command, cancellationToken));
}
