using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using PokemonSleep.Web.Models;
using PokemonSleep.Web.Service.IService;

namespace PokemonSleep.Web.Controllers
{
    public class PokemonController : Controller
    {

        private readonly IPokemonService _pokemonService;
        public PokemonController(IPokemonService pokemonService)
        {
            _pokemonService = pokemonService;
        }
        public async Task<IActionResult> PokemonIndex()
        {
            List<PokemonDto>? list = new();

            ResponseDto? response = await _pokemonService.GetAllPokemonAsync();

            if (response != null && response.IsSuccess)
            {
                list = JsonConvert.DeserializeObject<List<PokemonDto>>(Convert.ToString(response.Result));
            }

            return View(list);
        }
    }
}
