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_WORK_FORCE_DTOController(IDT_WORK_FORCEService dt_work_force_dtoService) : ControllerBase
    {
		#region CRUD de la table DT_WORK_FORCE
		// POST api/DT_WORK_FORCE_DTO
		[HttpPost]
		[Authorize(Roles = "Admin,Manager,User")]
		public async Task<ActionResult> Create([FromBody] DT_WORK_FORCE_DTO dt_work_force_dto)
		{
			if (await dt_work_force_dtoService.Create_Async(dt_work_force_dto))
			{
				return CreatedAtAction(nameof(GetById), new { ID_WORK_FORCE = dt_work_force_dto.ID_WORK_FORCE }, dt_work_force_dto);
			}
			return BadRequest("A member with this ID already exists.");
		}

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

		// PUT api/DT_WORK_FORCE_DTO/password/5
		[HttpPut("password/{ID_WORK_FORCE}")]
		[Authorize(Roles = "Admin")]
		public async Task<ActionResult> Update_Password(Guid ID_WORK_FORCE, [FromBody] DT_WORK_FORCE_DTO updatedDT_WORK_FORCE_DTO)
		{
			if (await dt_work_force_dtoService.Update_Password_Async(ID_WORK_FORCE, updatedDT_WORK_FORCE_DTO))
			{
				return NoContent();
			}
			return NotFound();
		}

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

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

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


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

		#endregion



    }
}
