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 COMPLEMENTOSCARRERAController : GenericoController<COMPLEMENTOSCARRERA, int>
    {
        public COMPLEMENTOSCARRERAController()
           : base()
        {
        }

        [Authorize(Policy = "LecturaPolicy")]
        [HttpGet("GruposEnumExtend/{idPersona}")]
        public async Task<IActionResult> GruposEnumExtend(int idPersona)
        {
            try
            {
                using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
                {
                    var motAdmin = context.COMPLEMENTOSCARRERA
                        .Include(v => v.IDGRUPONavigation)
                        .Include(v => v.IDTRAMONavigation)
                        .Where(p => p.IDPERSONA == idPersona)
                        .AsNoTracking().ToList();
                    if (motAdmin == null)
                        return NotFound();

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