using System.Threading.Tasks;
using GxPress.Repository.Interface;
using GxPress.Request.Department;
using GxPress.Result.Department;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using GxPress.Service.Interface.Department;
using System.Collections.Generic;

namespace GxPress.Api.AppControllers
{
    [Route("api/app/department")]
    [ApiController]
    [Authorize]
    public class DepartmentController : ControllerBase
    {
        private readonly IDepartmentRepository _departmentRepository;
        private readonly IDepartmentService departmentService;
        public DepartmentController(IDepartmentRepository departmentRepository, IDepartmentService departmentService)
        {
            _departmentRepository = departmentRepository;
            this.departmentService = departmentService;
        }

        /// <summary>
        /// 根据部门ID获取成员以及下级部门
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("user-list")]
        public async Task<DepartmentUserResult> GetDepartmentUserResult(DepartmentUserRequest request)
        {
            return await departmentService.GetDepartmentUserResultAsync(request);
        }
        [HttpGet("{userId}")]
        public async Task<IEnumerable<Entity.Department>> GetUserInDepartmentAsync(int userId)
        {
            return await departmentService.GetUserInDepartmentAsync(userId);
        }
    }
}