using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Kimuser.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using static IdentityServer4.IdentityServerConstants;

namespace Kimuser.Controllers
{
    [Authorize(LocalApi.PolicyName)]
    [Route("api/[controller]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IUserService _userService;
        public UserController(IUserService userService)
        {
            _userService = userService;
        }

        /// <summary>
        /// Tìm kiếm người dùng theo từ khóa
        /// </summary>
        /// <param name="keyword">Từ khóa</param>
        /// <returns></returns>
        [HttpGet("SearchUsers")]
        public async Task<IActionResult> SearchUsers(string keyword)
        {
            var result = await _userService.SearchUserAsync(keyword);
            return Ok(result);
        }

        /// <summary>
        /// Tìm kiếm người dùng theo từ khóa
        /// </summary>
        /// <param name="keyword">Từ khóa</param>
        /// <returns></returns>
        [HttpGet("SearchUsersByIds")]
        public async Task<IActionResult> GetUsers(string ids)
        {
            var result = await _userService.GetUsersAsync(ids);
            return Ok(result);
        }

    }
}
