using bdAntifraude.db;
using bdAntifraude.dbcontext;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using Microsoft.AspNetCore.Authorization;
using Serialize.Linq.Serializers;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;

namespace SwaggerAntifraude.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class ENUMERACIONESController : GenericoController<ENUMERACIONES, int>
    {
        public ENUMERACIONESController()
           : base()
        {
            Debug.WriteLine("aqui");
        }

        [Authorize(Policy = "LecturaPolicy")]
        [HttpGet("EnumeracionesGrupo/{codigoGrupo}")]
        public async Task<IActionResult> TiposExtend(string codigoGrupo)
        {
            try
            {
                using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
                {
                    var enumes = context.ENUMERACIONES.Include(v => v.IDGRUPOENUMERACIONNavigation)
                        .Where(p => p.IDGRUPOENUMERACIONNavigation.GRUPO == codigoGrupo)
                        .AsNoTracking().ToList();

                    if (enumes == null)
                        return NotFound();

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