using Modèle;
using Persistance;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business
{
    public class Manager
    {
        public ReadOnlyCollection<Requin> Requins { get; private set; }
        private List<Requin> requins = new List<Requin>();
        public Requin SelectedRequin { get; set; }

        /// <summary>
        ///  DéPENDANCE
        /// </summary>
    
        public IPersistanceManager Pers { get; private set; }

        /// <summary>
        /// constructeur avec INJECTION DE LA DéPENDANCE
        /// </summary>

        public Manager(IPersistanceManager pers)
        {
            Requins = new ReadOnlyCollection<Requin>(requins);
            Pers = pers;
        }
        public void LoadRequins()
        {
            requins.Clear();
            requins.AddRange(Pers.LoadRequins());
            if (requins.Count > 0)
            {
                SelectedRequin = requins.First();
            }
        }

        public void SaveRequins() 
        {
            Pers.SaveRequins(requins);   
        }

        public bool AjouterRequin(Requin req)
        {
            if (requins.Contains(req)){
                return false;

            }
            requins.Add(req);
            return true;
        }

        public bool SupprimerRequin(Requin req)
        {
            if (!requins.Contains(req))
            {
                return false;
            }
            requins.Remove(req);
            return true;
        }

        public Requin GetRequin(Requin req)
        {
            return requins.SingleOrDefault(r => r.Equals(req));
        }

        public bool ModifieRequin(Requin oldR, Requin newR)
        {
            if (!oldR.Equals(newR))
            {
                return false;
            }
            requins.Remove(oldR);
            requins.Add(newR);
            return true;
        }


    }
}