using System.Collections.Generic;
using System.Threading.Tasks;
using GxPress.Entity.WorkMeeting;
using GxPress.Repository.Interface.WorkMeeting;
using GxPress.Request.Admin.WorkMeeting;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace GxPress.Api.AdminControllers
{
    /// <summary>
    /// 会议
    /// </summary>
    [Route("api/admin/meeting")]
    [ApiController]
    [Authorize]
    public class AdminMeetingController : ControllerBase
    {
        private readonly IMeetingLocationRepository _meetingLocationRepository;
        private readonly IMeetingOrderRepository _meetingOrderRepository;
        private readonly IMeetingRepository _meetingRepository;
        private readonly IMeetingRoomRepository _meetingRoomRepository;
        private readonly IMeetingSummaryRepository _meetingSummaryRepository;

        public AdminMeetingController(IMeetingLocationRepository meetingLocationRepository, IMeetingOrderRepository meetingOrderRepository, IMeetingRepository meetingRepository, IMeetingRoomRepository meetingRoomRepository, IMeetingSummaryRepository meetingSummaryRepository)
        {
            _meetingLocationRepository = meetingLocationRepository;
            _meetingOrderRepository = meetingOrderRepository;
            _meetingRepository = meetingRepository;
            _meetingRoomRepository = meetingRoomRepository;
            _meetingSummaryRepository = meetingSummaryRepository;
        }

        /// <summary>
        /// 新增会议地点
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("location")]
        public async Task<MeetingLocation> LocationAdd([FromBody] MeetingLocation request)
        {
            request.Id = await _meetingLocationRepository.InsertAsync(request);
            return request;
        }

        /// <summary>
        /// 修改会议地点
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut("location")]
        public async Task LocationEdit([FromBody] MeetingLocation request)
        {
            await _meetingLocationRepository.UpdateAsync(request);
        }

        /// <summary>
        /// 获取会议地点列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("location")]
        public async Task<IEnumerable<MeetingLocation>> LocationList()
        {
            return await _meetingLocationRepository.GetListAsync();
        }

        /// <summary>
        /// 删除会议地点
        /// </summary>
        /// <returns></returns>
        [HttpDelete("location/{id}")]
        public async Task<bool> LocationRemove([FromRoute]int id)
        {
            return await _meetingLocationRepository.DeleteAsync(id);
        }

        /// <summary>
        /// 新增会议室
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("room")]
        public async Task<MeetingRoom> RoomAdd([FromBody] MeetingRoom request)
        {
            request.Id = await _meetingRoomRepository.InsertAsync(request);
            return request;
        }

        /// <summary>
        /// 修改会议室
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut("room")]
        public async Task RoomEdit([FromBody] MeetingRoom request)
        {
            await _meetingRoomRepository.UpdateAsync(request);
        }

        /// <summary>
        /// 获取会议地点列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("room")]
        public async Task<IEnumerable<MeetingRoom>> RoomList([FromQuery] MeetingRoomRequest request)
        {
            return await _meetingRoomRepository.GetListAsync(request.LocationId);
        }

        /// <summary>
        /// 删除会议地点
        /// </summary>
        /// <returns></returns>
        [HttpDelete("room/{id}")]
        public async Task<bool> RoomRemove([FromRoute]int id)
        {
            return await _meetingRoomRepository.DeleteAsync(id);
        }
    }
}