using Asp.Versioning;
using Core.Blueprint.Application.UsesCases.SQL.Input;
using Core.Blueprint.Application.UsesCases.SQL.Ports;
using Lib.Architecture.BuildingBlocks;
using Microsoft.AspNetCore.Mvc;
namespace Core.Cerberos.Service.API.Controllers
{
    /// 
    /// Handles all services and business rules related to .
    /// 
    [ApiVersion("1.0")]
    [Route("api/v{api-version:apiVersion}/[controller]")]
    [Produces("application/json")]
    [ApiController]
    public class SQLUserProjectController : ControllerBase
    {
        private readonly IComponentHandler createUserProjectHandler;
        private readonly IComponentHandler getAllUserProjectsHandler;
        private readonly IComponentHandler getUserProjectHandler;
        private readonly IComponentHandler updateUserProjectHandler;
        private readonly IComponentHandler deleteUserProjectStatusHandler;
        private readonly ISQLPort port;
        /// 
        /// Handles all services and business rules related to .
        /// 
        public SQLUserProjectController(
            IComponentHandler getUserProjectHandler,
            IComponentHandler getAllUserProjectsHandler,
            IComponentHandler createUserProjectHandler,
            IComponentHandler updateUserProjectHandler,
            IComponentHandler deleteUserProjectStatusHandler,
            ISQLPort port
            )
        {
            this.createUserProjectHandler = createUserProjectHandler;
            this.updateUserProjectHandler = updateUserProjectHandler;
            this.deleteUserProjectStatusHandler = deleteUserProjectStatusHandler;
            this.getAllUserProjectsHandler = getAllUserProjectsHandler;
            this.getUserProjectHandler = getUserProjectHandler;
            this.port = port;
        }
        /// 
        /// Creates a new UserProject.
        /// 
        [HttpPost("Create")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status204NoContent)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
        [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        [ProducesResponseType(StatusCodes.Status400BadRequest)]
        public async Task CreateUserProjectAsync([FromBody] CreateUserProjectRequest newUserProject, CancellationToken cancellationToken = default)
        {
            await createUserProjectHandler.ExecuteAsync(newUserProject, cancellationToken).ConfigureAwait(false);
            return port.ViewModel;
        }
        /// 
        /// Gets all UserProjects.
        /// 
        [HttpGet("GetAll")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status204NoContent)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
        [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        [ProducesResponseType(StatusCodes.Status400BadRequest)]
        public async Task GetAllUserProjectsAsync(CancellationToken cancellationToken)
        {
            await getAllUserProjectsHandler.ExecuteAsync(new GetAllUserProjectsRequest { }, cancellationToken).ConfigureAwait(false);
            return port.ViewModel;
        }
        /// 
        /// Gets the UserProject by identifier.
        /// 
        [HttpPost]
        [Route("GetById")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status204NoContent)]
        [ProducesResponseType(StatusCodes.Status400BadRequest)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
        [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task GetUserProjectById([FromBody] GetUserProjectRequest request, CancellationToken cancellationToken)
        {
            if (request.Id <= 0) { return BadRequest("Invalid UserProject identifier"); }
            await getUserProjectHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
            return port.ViewModel;
        }
        /// 
        /// Updates a full UserProject by identifier.
        /// 
        [HttpPut("Update")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status204NoContent)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
        [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        [ProducesResponseType(StatusCodes.Status400BadRequest)]
        public async Task UpdateUserProjectAsync([FromBody] UpdateUserProjectRequest request, CancellationToken cancellationToken = default)
        {
            if (request.Id <= 0) { return BadRequest("Invalid UserProject identifier"); }
            await updateUserProjectHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
            return port.ViewModel;
        }
        /// 
        /// Deletes a UserProject.
        /// 
        [HttpDelete]
        [Route("Delete")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status204NoContent)]
        [ProducesResponseType(StatusCodes.Status400BadRequest)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
        [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task DeleteUserProjectStatusAsync([FromBody] DeleteUserProjectRequest request,
                                                                     CancellationToken cancellationToken)
        {
            if (request.Id <= 0) { return BadRequest("Invalid UserProject identifier"); }
            await deleteUserProjectStatusHandler.ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
            return port.ViewModel;
        }
    }
}