using Azure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PokemonSleepAPI.Models.Dto;
using PokemonSleepAPI.Models;
using AutoMapper;
using PokemonSleepAPI.Data;

namespace PokemonSleepAPI.Controllers
{
    [Route("api/nature")]
    [ApiController]
    public class PokemonNatureController : ControllerBase
    {
        private readonly PokemonDbContext _db;
        private ResponseDto _response;
        private IMapper _mapper;

        public PokemonNatureController(PokemonDbContext db, IMapper mapper)
        {
            _db = db;
            _mapper = mapper;
            _response = new ResponseDto();
        }
        /* Get all Pokemon Natures */
        [HttpGet]
        public ResponseDto GetAllPokemonNatures()
        {
            try
            {
                IEnumerable<PokemonNature> objList = _db.PokemonNatures.ToList();
                _response.Message = "Pokemon Natures found.";
                _response.Result = _mapper.Map<IEnumerable<PokemonNatureDto>>(objList);

            }
            catch (Exception ex)
            {
                _response.IsSuccess = false;
                _response.Message = ex.Message;
            }
            return _response;
        }
    }
}
