using Microsoft.AspNetCore.Mvc;
using WCS.BLL.Services.IService;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.User;

namespace WCS.WebApi.Controllers
{
    /// <summary>
    /// 权限/用户界面的接口
    /// </summary>
    [ApiController]
    [Route("[controller]")]
    public class UserController : ControllerBase
    {
        public IUserService _userService { get; set; }

        public UserController(IUserService userService)
        {
            _userService = userService;
        }

        [Route("getUsers")]
        [HttpPost(Name = "getUsers")]
        public async Task<ResponseBase> getUsers(GetUsersRequest request)
        {
            return await _userService.GetUsers(request);
        }

        [Route("addUser")]
        [HttpPost(Name = "addUser")]
        public async Task<ResponseBase> addUser(AddUserRequest<UserModel> request)
        {
            return await _userService.AddUser(request);
        }

        [Route("getRoles")]
        [HttpPost(Name = "getRoles")]
        public async Task<ResponseBase> getRoles(GetUsersRequest request)
        {
            return await _userService.GetRoles(request);
        }

        [Route("addRole")]
        [HttpPost(Name = "addRole")]
        public async Task<ResponseBase> addRole(AddRoleRequest<RoleModel> request)
        {
            return await _userService.AddRole(request);
        }

        [Route("userLogin")]
        [HttpPost(Name = "userLogin")]
        public async Task<ResponseBase> userLogin(UserLoginRequest request)
        {
            //获取调用设备的Ip地址
            request.WebSocketIpAddress = HttpContext?.Connection?.RemoteIpAddress?.ToString();
            return await _userService.UserLogin(request);
        }
    }
}
