using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting;
using Meezi.API.Models.Discover;
using Meezi.API.Models.Public;
using Meezi.API.Services;
using Meezi.Shared;

namespace Meezi.API.Controllers;

[ApiController]
[AllowAnonymous]
[Route("api/public")]
public class PublicDiscoverController : ControllerBase
{
    [HttpGet("discover-profile/taxonomy")]
    [EnableRateLimiting("public-read")]
    public IActionResult Taxonomy() =>
        Ok(new ApiResponse<DiscoverProfileTaxonomyDto>(true, CafeDiscoverProfileMapping.Taxonomy()));

    /// <summary>
    /// Parse a free-text Persian query and return the filter hints the NLP engine detected.
    /// Used by the frontend to show "detected filters" chips under the AI search box.
    /// </summary>
    [HttpGet("discover/nlp-parse")]
    [EnableRateLimiting("public-read")]
    public IActionResult NlpParse([FromQuery] string q)
    {
        if (string.IsNullOrWhiteSpace(q))
            return Ok(new ApiResponse<DiscoverNlpHintsDto>(true, DiscoverNlpHintsDto.Empty));

        var hints = DiscoverNlpParser.Parse(q);
        var dto = new DiscoverNlpHintsDto(
            hints.Themes,
            hints.Vibes,
            hints.Occasions,
            hints.SpaceFeatures,
            hints.NoiseLevel,
            hints.PriceTier,
            hints.Size);

        return Ok(new ApiResponse<DiscoverNlpHintsDto>(true, dto));
    }
}
