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

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

        [HttpGet]
        public override async Task<IActionResult> GetAll()
        {
            try
            {
                using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
                {
                    var entities = await context.FIESTAS
                        .AsNoTracking()
                        .ToListAsync();                   
                    return Ok(entities);
                }
            }
            catch (Exception ex)
            {
                return StatusCode(500, $"Error interno del servidor: {ex.Message}");
            }
        }

        [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.FIESTAS                       
                        .AsNoTracking()
                        .FirstOrDefault(v => v.IDFIESTA == id);



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

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


    }
}
