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

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

        [Authorize(Policy = "LecturaPolicy")]
        [HttpGet("TiposExtend/{idMotivo}")]
        public async Task<IActionResult> TiposExtend(int idMotivo)
        {
            try
            {
                using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
                {
                    var motAdmin = context.MOTIVOS_ADMINISTRATIVOS.Include(v => v.IDTIPOAPTOSNavigation).FirstOrDefault(p => p.IDMOTIVO == idMotivo);
                    if (motAdmin == null)
                        return NotFound();

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

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

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