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

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

        public PokemonSubskillController(PokemonDbContext db, IMapper mapper)
        {
            _db = db;
            _mapper = mapper;
            _response = new ResponseDto();
        }

        /* Get all Pokemon Subskills */
        [HttpGet]
        public ResponseDto GetAllPokemonSubskills()
        {
            try
            {
                IEnumerable<PokemonSubskill> objList = _db.PokemonSubskills .ToList();
                _response.Message = "Pokemon Subskills found.";
                _response.Result = _mapper.Map<IEnumerable<PokemonSubskillDto>>(objList);

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