using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Windows.Input;
using MauiAppStock.Models;
using MauiAppStock.Data;
using MauiAppStock.Helpers;

namespace MauiAppStock.ViewModels
{
    public class PiecesViewModel : BaseViewModel
    {
        public ObservableCollection<Piece> Pieces { get; set; }
        public ICommand LoadPiecesCommand { get; }

        public PiecesViewModel()
        {
            Pieces = new ObservableCollection<Piece>();
            LoadPiecesCommand = new AsyncCommand(LoadPieces);
        }

        private async Task LoadPieces()
        {
            Pieces.Clear();
            var piecesList = await Database.GetPiecesAsync();
            foreach (var piece in piecesList)
            {
                Pieces.Add(piece);
            }
        }
    }
}