using Microsoft.AspNetCore.Authorization;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MTWorkHR.Application.Filters;
using MTWorkHR.Application.Identity;
using MTWorkHR.Application.Models;
using MTWorkHR.Application.Services.Interfaces;
using MTWorkHR.Identity.Services;

namespace MTWorkHR.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [AppAuthorize]
    public class TeamController : ControllerBase
    {
        private readonly ITeamService _TeamService;
        public TeamController(ITeamService UserTeamService)
        {
            this._TeamService = UserTeamService;
        }
        [HttpGet("GetAll")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "Team")]
        public async Task<ActionResult<List<TeamDto>>> GetAll([FromQuery] PagingInputDto pagingInput)
        {
            return Ok(await _TeamService.GetAll(pagingInput));
        }
        [HttpGet("Get")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "Team")]

        public async Task<ActionResult<TeamDto>> Get(long TeamId)
        {
            return Ok(await _TeamService.GetById(TeamId));
        }


        [HttpPost("Create")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "Team.Create")]

        public async Task<ActionResult<TeamDto>> Create([FromBody] TeamDto input)
        {
            return await _TeamService.Create(input);
        }

        [HttpPost("Update")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "Team.Update")]

        public async Task<ActionResult<TeamDto>> Update([FromBody] TeamDto input)
        {
            return await _TeamService.Update(input);
        }

        [HttpDelete("Delete")]
        [ProducesResponseType(StatusCodes.Status200OK)]
          [AppAuthorize(Permissions = "Team.Delete")]

        public async Task Delete([FromQuery] long id)
        {
            await _TeamService.Delete(id);
        }

        [HttpPost("AssignAdminManager")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "Team.Update")]
        public async Task<bool> AssignAdminManager([FromBody] TeamUserDto teamUser)
        {
            return await _TeamService.AssignAdminManager(teamUser);
        }

        [HttpGet("GetTeamListForUser")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "Team.Update")]
        public async Task<IList<TeamDto>> GetTeamListForUser(string userId)
        {
            return await _TeamService.GetTeamListForUser(userId);
        }

        

    }
}
