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;
using MTWorkHR.Application.Services.Interfaces;
using MTWorkHR.Identity.Services;

namespace MTWorkHR.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [AppAuthorize]
    public class OrderRequestController : ControllerBase
    {
        private readonly IOrderRequestService _LeaveRequestService;
        public OrderRequestController(IOrderRequestService UserLeaveRequestService)
        {
            this._LeaveRequestService = UserLeaveRequestService;
        }
        [HttpGet("GetAll")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "OrderRequest")]
        public async Task<ActionResult<List<OrderRequestDto>>> GetAll([FromQuery] OrderPagingInputDto pagingInput)
        {
            return Ok(await _LeaveRequestService.GetAll(pagingInput));
        }
        [HttpGet("Get")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "OrderRequest")]
        public async Task<ActionResult<OrderRequestDto>> Get(long OrderRequestId)
        {
            return Ok(await _LeaveRequestService.GetById(OrderRequestId));
        }

        [HttpGet("GetOverTime")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "OrderRequest")]
        public async Task<ActionResult<OverTimeDto>> GetOverTime(long OrderRequestId)
        {
            return Ok(await _LeaveRequestService.GetOverTime(OrderRequestId));
        }

        [HttpGet("GetBusinessTrip")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "OrderRequest")]
        public async Task<ActionResult<BusinessTripDto>> GetBusinessTrip(long OrderRequestId)
        {
            return Ok(await _LeaveRequestService.GetBusinessTrip(OrderRequestId));
        }
        [HttpGet("GetCourse")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "OrderRequest")]
        public async Task<ActionResult<OrderRequestDto>> GetCourse(long OrderRequestId)
        {
            return Ok(await _LeaveRequestService.GetById(OrderRequestId));
        }

        [HttpGet("GetServiceCertificate")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "OrderRequest")]
        public async Task<ActionResult<ServiceCertificateRequestDto>> GetServiceCertificate(long OrderRequestId)
        {
            return Ok(await _LeaveRequestService.GetServiceCertificate(OrderRequestId));
        }

        [HttpGet("GetOther")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "OrderRequest")]
        public async Task<ActionResult<OrderRequestDto>> GetOther(long OrderRequestId)
        {
            return Ok(await _LeaveRequestService.GetById(OrderRequestId));
        }

        [HttpPost("CreateLeave")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "OrderRequest.Create")]
        public async Task<ActionResult<OrderRequestDto>> Create([FromBody] OrderRequestDto input)
        {
            return await _LeaveRequestService.Create(input);
        }


        [HttpPost("CreateOverTime")]
        public async Task<ActionResult<OrderRequestDto>> CreateOverTime([FromBody] OverTimeDto overtimeDto)
        {
            var orderRequest = await _LeaveRequestService.Create(overtimeDto);
            return orderRequest;
        }

        [HttpPost("CreateBusinessTrip")]
        public async Task<ActionResult<OrderRequestDto>> CreateBusinessTrip([FromBody] BusinessTripDto businessTripDto)
        {
            var orderRequest = await _LeaveRequestService.Create(businessTripDto);
            return orderRequest;

        }

        [HttpPost("CreateCourse")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "OrderRequest.Create")]
        public async Task<ActionResult<OrderRequestDto>> CreateCourse([FromBody] OrderRequestDto input)
        {
            return await _LeaveRequestService.Create(input);
        }


        [HttpPost("CreateServiceCertificate")]
        public async Task<ActionResult<OrderRequestDto>> CreateServiceCertificate([FromBody] ServiceCertificateRequestDto serviceCertificate)
        {
            var orderRequest = await _LeaveRequestService.Create(serviceCertificate);
            return orderRequest;

        }

        [HttpPost("CreateOther")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "OrderRequest.Create")]
        public async Task<ActionResult<OrderRequestDto>> CreateOther([FromBody] OrderRequestDto input)
        {
            return await _LeaveRequestService.Create(input);
        }

        [HttpPost("Update")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "OrderRequest.Update")]
        public async Task<ActionResult<OrderRequestDto>> Update([FromBody] OrderRequestDto input)
        {
            return await _LeaveRequestService.Update(input);
        }

        [HttpDelete("Delete")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "OrderRequest.Delete")]
        public async Task Delete([FromQuery]long id)
        {
            await _LeaveRequestService.Delete(id);
        }
        [HttpPost("ChangeStatus")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [AppAuthorize(Permissions = "OrderRequest.Update")]
        public async Task<ActionResult<OrderRequestDto>> ChangeStatus([FromBody] OrderStatusDto input)
        {
            return await _LeaveRequestService.ChangeStatus(input.OrderId, input.StatusId);
        }


    }
}
