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

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

        [Authorize(Policy = "LecturaPolicy")]
        [HttpGet("{id}")]
        public override IActionResult GetById(int id)
        {
            try
            {
                using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
                {
                    //var dbSet = context.Set<VIDA_ADMINISTRATIVA>();
                    var entities = context.PERIODOSSILTRA
                        .Include(x => x.TRAMOSSILTRA)
                        .ThenInclude(v => v.IDTIPOTRAMONavigation)                          
                        .ThenInclude(y => y.IDTIPOTRAMOFICHEROXMLNavigation)
                        .Include(x => x.IDTIPOLIQUIDACIONNavigation)
                        .Include(x => x.IDESTADONavigation)
                        .AsNoTracking()
                        .FirstOrDefault(v => v.IDPERIODOSILTRA == id);



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

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