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

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

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

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

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


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

		#endregion

		#region By_ID_WORK_FORCE
		// GET: api/DT_LOGS_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_logs = await dt_logs_dtoService.GetAll_By_ID_WORK_FORCE_Async(ID_WORK_FORCE);
			return Ok(dt_logs);
		}

		// GET: api/DT_LOGS_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_logs = await dt_logs_dtoService.GetCount_By_ID_WORK_FORCE_Async(ID_WORK_FORCE);
			return Ok(dt_logs);
		}

		// GET: api/DT_LOGS_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_logs_dtoService.Delete_By_ID_WORK_FORCE_Async(ID_WORK_FORCE))
			{
				return NoContent();
			}
			return NotFound();
		}

		#endregion



    }
}
