using DataLayer.Interfaces;
using Domain.Weapons;
using Domain.XML_Model;
using Microsoft.AspNetCore.Components;

namespace Deathwatch.Pages.Weapon
{
    public partial class WeaponList
    {
        [Inject]
        public IAbstractRepository<Arme>? WeaponRepository { get; set; }

        public List<Weapon> Weapons { get; set; } = new List<Weapon>();
        public Weapon? SelectedWeapon { get; set; }

        protected override async Task OnInitializedAsync()
        {
            var armes = (await WeaponRepository?.GetAll()).OrderBy(a => a.Nom).ToList();
            armes.ForEach(a => Weapons.Add(new Weapon
            {
                Arme = a
            }));
            SelectedWeapon = Weapons.FirstOrDefault();
        }

    }
}
