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

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

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

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

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


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

		#endregion

		#region By_ID_WORK_FORCE
		// GET: api/DT_CONVERSATION_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_conversation = await dt_conversation_dtoService.GetAll_By_ID_WORK_FORCE_Async(ID_WORK_FORCE);
			return Ok(dt_conversation);
		}

		// GET: api/DT_CONVERSATION_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_conversation = await dt_conversation_dtoService.GetCount_By_ID_WORK_FORCE_Async(ID_WORK_FORCE);
			return Ok(dt_conversation);
		}

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

		#endregion



    }
}
