using System.ComponentModel.DataAnnotations;
using Asp.Versioning;
using Baya.Application.Features.ServiceAreas.Commands.AddNurseServiceArea;
using Baya.Application.Features.ServiceAreas.Commands.RemoveNurseServiceArea;
using Baya.Application.Features.ServiceAreas.Queries.ListMyServiceAreas;
using Baya.Application.Models.Common;
using Baya.Application.Models.Geography;
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]
[Display(Description = "The signed-in nurse's declared service areas (where they will travel)")]
public sealed class NurseServiceAreasController(ISender sender) : BaseController
{
    [HttpPost("[action]")]
    [ProducesOkApiResponseType<NurseServiceAreaDto>]
    public async Task<IActionResult> Add(AddNurseServiceAreaCommand command, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(command, cancellationToken));

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

    [HttpGet("[action]")]
    [ProducesOkApiResponseType<PagedResult<NurseServiceAreaDto>>]
    public async Task<IActionResult> List([FromQuery] ListMyServiceAreasQuery query, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(query, cancellationToken));
}
