using ReAct_PME.Application;
using ReAct_PME.Domain;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;


namespace ReAct_PME.Api.Controllers
{
	[ApiController]
	[Route("api/[controller]")]

    public partial class DT_ROLE_DTOController(IDT_ROLEService dt_role_dtoService) : ControllerBase
    {
		#region CRUD de la table DT_ROLE
		// POST api/DT_ROLE_DTO
		[HttpPost]
		[Authorize(Roles = "Admin,Manager,User")]
		public async Task<ActionResult> Create([FromBody] DT_ROLE_DTO dt_role_dto)
		{
			if (await dt_role_dtoService.Create_Async(dt_role_dto))
			{
				return CreatedAtAction(nameof(GetById), new { ID_ROLE = dt_role_dto.ID_ROLE }, dt_role_dto);
			}
			return BadRequest("A member with this ID already exists.");
		}

		// PUT api/DT_ROLE_DTO/5
		[HttpPut("{ID_ROLE}")]
		[Authorize(Roles = "Admin,Manager,User")]
		public async Task<ActionResult> Update(Guid ID_ROLE, [FromBody] DT_ROLE_DTO updatedDT_ROLE_DTO)
		{
			if (await dt_role_dtoService.Update_Async(ID_ROLE, updatedDT_ROLE_DTO))
			{
				return NoContent();
			}
			return NotFound();
		}

		// DELETE api/DT_ROLE_DTO/5
		[HttpDelete("{ID_ROLE}")]
		[Authorize(Roles = "Admin,Manager,User")]
		public async Task<ActionResult> Delete(Guid ID_ROLE)
		{
			if (await dt_role_dtoService.Delete_Async(ID_ROLE))
			{
				return NoContent();
			}
			return NotFound();
		}

		// GET: api/DT_ROLE_DTO/ADMIN
		[HttpGet("ADMIN")]
		[Authorize(Roles = "Admin,Manager,User")]
		public async Task<ActionResult> GetAll()
		{
			var dt_role_dto = await dt_role_dtoService.GetAll_Async();
			return Ok(dt_role_dto);
		}

		// GET: api/DT_ROLE_DTO
		[HttpGet]
		[Authorize(Roles = "Admin,Manager,User")]
		public async Task<ActionResult> GetAll_Actifs()
		{
			var dt_role_dto = await dt_role_dtoService.GetAll_Async(true);
			return Ok(dt_role_dto);
		}


		// GET: api/DT_ROLE_DTO/5
		[HttpGet("{ID_ROLE}")]
		[Authorize(Roles = "Admin,Manager,User")]
		public async Task<ActionResult<DT_ROLE_DTO>>? GetById(Guid ID_ROLE)
		{
			var dt_role_dto = await dt_role_dtoService.GetById_Async(ID_ROLE);
			if (dt_role_dto == null)
			{
				return NotFound();
			}
			return Ok(dt_role_dto);
		}

		#endregion



    }
}
