using bdAntifraude.db;
using bdAntifraude.dbcontext;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;

namespace SwaggerAntifraude.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class CUERPOController : GenericoController<CUERPO, int>
    {
        public CUERPOController()
             : base()
        {
        }


        [Authorize(Policy = "LecturaPolicy")]
        [HttpGet("GrupoExtend")]
        public async Task<IActionResult> GrupoExtend()
        {
            try
            {
                using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
                {
                    var motAdmin = await context.CUERPO.Include(v => v.IDGRUPONavigation).AsNoTracking().ToListAsync();
                    if (motAdmin == null)
                        return NotFound();

                    return Ok(motAdmin);
                }
            }
            catch (Exception ex)
            {
                return StatusCode(500, $"Error interno del servidor: {ex.Message}");
            }
        }
    }
}
