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

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

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

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

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


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

		#endregion

		#region By_ID_WORK_FORCE
		// GET: api/DT_WORK_FORCE_ROLE_DTO/ID_WORK_FORCE/5
		[HttpGet("ID_WORK_FORCE/{ID_WORK_FORCE}")]
		[Authorize(Roles = "Admin,Manager,User")]
		public async Task<ActionResult> GetAll_By_ID_WORK_FORCE_Async(Guid ID_WORK_FORCE)
		{
			var dt_work_force_role = await dt_work_force_role_dtoService.GetAll_By_ID_WORK_FORCE_Async(ID_WORK_FORCE);
			return Ok(dt_work_force_role);
		}

		// GET: api/DT_WORK_FORCE_ROLE_DTO/ID_WORK_FORCE/count/5
		[HttpGet("ID_WORK_FORCE/count/{ID_WORK_FORCE}")]
		[Authorize(Roles = "Admin,Manager,User")]
		public async Task<ActionResult> GetCount_By_ID_WORK_FORCE_Async(Guid ID_WORK_FORCE)
		{
			var dt_work_force_role = await dt_work_force_role_dtoService.GetCount_By_ID_WORK_FORCE_Async(ID_WORK_FORCE);
			return Ok(dt_work_force_role);
		}

		// GET: api/DT_WORK_FORCE_ROLE_DTO/ID_WORK_FORCE/del/5
		[HttpDelete("ID_WORK_FORCE/del/{ID_WORK_FORCE}")]
		[Authorize(Roles = "Admin,Manager,User")]
		public async Task<ActionResult> Delete_By_ID_WORK_FORCE_Async(Guid ID_WORK_FORCE)
		{
			if(await dt_work_force_role_dtoService.Delete_By_ID_WORK_FORCE_Async(ID_WORK_FORCE))
			{
				return NoContent();
			}
			return NotFound();
		}

		#endregion

		#region By_ID_ROLE
		// GET: api/DT_WORK_FORCE_ROLE_DTO/ID_ROLE/5
		[HttpGet("ID_ROLE/{ID_ROLE}")]
		[Authorize(Roles = "Admin,Manager,User")]
		public async Task<ActionResult> GetAll_By_ID_ROLE_Async(Guid ID_ROLE)
		{
			var dt_work_force_role = await dt_work_force_role_dtoService.GetAll_By_ID_ROLE_Async(ID_ROLE);
			return Ok(dt_work_force_role);
		}

		// GET: api/DT_WORK_FORCE_ROLE_DTO/ID_ROLE/count/5
		[HttpGet("ID_ROLE/count/{ID_ROLE}")]
		[Authorize(Roles = "Admin,Manager,User")]
		public async Task<ActionResult> GetCount_By_ID_ROLE_Async(Guid ID_ROLE)
		{
			var dt_work_force_role = await dt_work_force_role_dtoService.GetCount_By_ID_ROLE_Async(ID_ROLE);
			return Ok(dt_work_force_role);
		}

		// GET: api/DT_WORK_FORCE_ROLE_DTO/ID_ROLE/del/5
		[HttpDelete("ID_ROLE/del/{ID_ROLE}")]
		[Authorize(Roles = "Admin,Manager,User")]
		public async Task<ActionResult> Delete_By_ID_ROLE_Async(Guid ID_ROLE)
		{
			if(await dt_work_force_role_dtoService.Delete_By_ID_ROLE_Async(ID_ROLE))
			{
				return NoContent();
			}
			return NotFound();
		}

		#endregion



    }
}
