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

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

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

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

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


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

		#endregion

		#region By_ID_CONVERSATION
		// GET: api/DT_CONVERSATION_LIGNE_DTO/ID_CONVERSATION/5
		[HttpGet("ID_CONVERSATION/{ID_CONVERSATION}")]
		[Authorize(Roles = "Admin,Manager,User")]
		public async Task<ActionResult> GetAll_By_ID_CONVERSATION_Async(Guid ID_CONVERSATION)
		{
			var dt_conversation_ligne = await dt_conversation_ligne_dtoService.GetAll_By_ID_CONVERSATION_Async(ID_CONVERSATION);
			return Ok(dt_conversation_ligne);
		}

		// GET: api/DT_CONVERSATION_LIGNE_DTO/ID_CONVERSATION/count/5
		[HttpGet("ID_CONVERSATION/count/{ID_CONVERSATION}")]
		[Authorize(Roles = "Admin,Manager,User")]
		public async Task<ActionResult> GetCount_By_ID_CONVERSATION_Async(Guid ID_CONVERSATION)
		{
			var dt_conversation_ligne = await dt_conversation_ligne_dtoService.GetCount_By_ID_CONVERSATION_Async(ID_CONVERSATION);
			return Ok(dt_conversation_ligne);
		}

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

		#endregion



    }
}
