using System;
using System.Collections.Generic;
using TheGameExtreme.model;
using TheGameExtreme.model.card;
using TheGameExtreme.model.@event;

namespace TheGameExtreme.viewmodel
{
    public class PlayerVM
    {

        public Player View { get; set; }
        public string Pseudo { get; set; }
        private List<CardVM> cardList = new List<CardVM>();
        //public event EventHandler<HandCardChangedEventArgs> HandCardChanged;

        public PlayerVM(Player view)
        {
            View = view;

            Pseudo = view.Pseudo;
            view.getCardList().ForEach(card => cardList.Add(new CardVM(card)));

            View.HandCardChanged += OnHandCardChanged;
        }

        private void OnHandCardChanged(object sender, HandCardChangedEventArgs args)
        {
            if (args.NewCard == null)
            {
                cardList.RemoveAt(args.Position);
            }
            else
            {
                cardList.Insert(args.Position, new CardVM(args.NewCard));
            }
        }

        public void pioche(CardVM card)
        {
            View.pioche(card.View);
        }

        public List<CardVM> getCardList()
        {
            return cardList;
        }
    }
}
