using System;
using System.Threading.Tasks;
using Domain;
using Microsoft.AspNetCore.Mvc;
using Services.Interfaces;

namespace Warhammer.Controllers.Players;

public class PlayerController : Controller
{
    private readonly IPlayerService _playerService;

    public PlayerController(IPlayerService playerService)
    {
        CurrentPlayer = new Player();
        _playerService = playerService;
    }

    private Player CurrentPlayer { get; }

    public async Task<IActionResult> PlayersAsync()
    {
        try
        {
            var players = await _playerService.GetAll();
            return View("Players/PlayerListView", players);
        }
        catch (Exception e)
        {
            throw;
        }
    }

    public async Task<IActionResult> PlayerDetailsAsync(int id)
    {
        try
        {
            var player = await _playerService.GetById(id);
            return View("Players/PlayerDetail", player);
        }
        catch (Exception e)
        {
            throw e;
        }
    }

    [HttpPost]
    public async Task<IActionResult> IndexAsync()
    {
        try
        {
            var player = await _playerService.GetById(0);
            return View("Players/PlayerDetail", player);
        }
        catch (Exception e)
        {
            throw e;
        }
    }
}