using System.ComponentModel.DataAnnotations;
using Asp.Versioning;
using Baya.Application.Features.Nurses.Queries.GetNursePublicProfile;
using Baya.Application.Features.Reviews.Queries.GetTagAggregates;
using Baya.Application.Features.Reviews.Queries.ListReviewsForNurse;
using Baya.Application.Features.Verification.Queries.GetTrustBadge;
using Baya.Application.Models.Nurses;
using Baya.Application.Models.Reviews;
using Baya.Application.Models.Verification;
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]")]
[AllowAnonymous]
[Display(Description = "Public nurse read surface (the verified trust badge + published reviews)")]
public sealed class NursesController(ISender sender) : BaseController
{
    // Public: the verified badge exposes credential *types* held, never the encrypted numbers.
    [HttpGet("{nurseId}/[action]")]
    [ProducesOkApiResponseType<TrustBadgeDto>]
    public async Task<IActionResult> TrustBadge(long nurseId, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(new GetVerifiedTrustBadgeQuery(nurseId), cancellationToken));

    // Public: the aggregated discovery detail (identity + aggregates + verification + services + latest review).
    [HttpGet("{nurseId}/[action]")]
    [ProducesOkApiResponseType<NursePublicProfileDto>]
    public async Task<IActionResult> Profile(long nurseId, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(new GetNursePublicProfileQuery(nurseId), cancellationToken));

    // Public: published reviews only (the publish gate is enforced in the query) + the cached rating aggregate.
    [HttpGet("{nurseProfileId}/reviews")]
    [ProducesOkApiResponseType<NurseReviewsResult>]
    public async Task<IActionResult> Reviews(long nurseProfileId, [FromQuery] int page = 1, [FromQuery] int pageSize = 20, CancellationToken cancellationToken = default)
        => OperationResult(await sender.Send(new ListReviewsForNurseQuery(nurseProfileId, page, pageSize), cancellationToken));

    // Public: the per-nurse tag rollup ("% punctual", …) over published reviews.
    [HttpGet("{nurseProfileId}/review_tags")]
    [ProducesOkApiResponseType<NurseTagAggregatesResult>]
    public async Task<IActionResult> ReviewTags(long nurseProfileId, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(new GetTagAggregatesQuery(nurseProfileId), cancellationToken));
}
