using Lada.Framework.DTO.SmartTable;
using Ladaer.BackEnd.Infrastructures.Services.Cms;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Ladaer.BackEnd.Controllers.Cms
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class TagController : ControllerBase
    {
        private readonly ITagService _tagService;

        public TagController(ITagService tagService)
        {
            _tagService = tagService;
        }

        /// <summary>
        /// T? d?ng hoàn thành t? khóa t́m ki?m th?
        /// </summary>
        /// <param name="keyword">T? khóa t́m ki?m</param>
        /// <returns>Danh sách các th? g?i ư</returns>
        [HttpGet("Autocomplete")]
        [Authorize(Roles = "Tag.Autocomplete")]
        public async Task<IActionResult> Autocomplete(string? keyword)
        {
            var suggests = await _tagService.TagAutocomplete(keyword);
            return Ok(suggests);
        }

        /// <summary>
        /// T́m ki?m các th? d?a trên tham s? SmartTableParam
        /// </summary>
        /// <param name="param">Tham s? t́m ki?m</param>
        /// <returns>Danh sách các th? phù h?p</returns>
        [HttpPost("Search")]
        [Authorize(Roles = "Tag.Search")]
        public async Task<IActionResult> Search([FromBody] SmartTableParam param)
        {
            var tags = await _tagService.Search(param);
            return Ok(tags);
        }
    }
}
