using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FSI.Lib.Guis.WebRadio.Player
{
    public class RadioPlayer : IPlayer
    {


        //private readonly IDisplayEngine _displayEngine;
        private readonly Lib.Guis.WebRadio.Player.SoundEngine.ISoundEngine _soundEngine;

        public StationManager StationManager { get; set; }

        public RadioPlayer(SoundEngine.ISoundEngine soundEngine)//RadioPlayer(IDisplayEngine displayEngine, ISoundEngine soundEngine)
        {
            //_displayEngine = displayEngine;
            _soundEngine = soundEngine;
            //StationManager = ApplicationDataHandler.Load();
            StationManager.PlayingStationDeleted += StationManager_PlayingStationDeleted;
        }

        private void StationManager_PlayingStationDeleted(object sender, EventArgs e) => _soundEngine.Stop();

        public void Run()
        {
            _soundEngine.Play(StationManager.PlayingStation);
            //AvailableActions.PlayerAction playerAction = AvailableActions.PlayerAction.None;
            //do
            //{
            //    //_displayEngine.Draw(StationManager.Stations);
            //    playerAction = Console.ReadKey().ToPlayerAction();
            //    //switch (playerAction)
            //    //{
            //    //    case AvailableActions.PlayerAction.None:
            //    //        break;
            //    //    case AvailableActions.PlayerAction.Quit:
            //    //        break;
            //    //    case AvailableActions.PlayerAction.Add:
            //    //        if (!StationManager.AddStation(_displayEngine.AddStation()))
            //    //        {
            //    //            //_displayEngine.ShowMessage(new Message("This station could not be added. Check URL", MessageType.Critical));
            //    //        }
            //    //        break;
            //    //    case AvailableActions.PlayerAction.VolumeDown:
            //    //        _soundEngine.VolumeDown();
            //    //        break;
            //    //    case AvailableActions.PlayerAction.VolumeUp:
            //    //        _soundEngine.VolumeUp();
            //    //        break;
            //    //    case AvailableActions.PlayerAction.Next:
            //    //        _soundEngine.Play(StationManager.Next());
            //    //        break;
            //    //    case AvailableActions.PlayerAction.Previous:
            //    //        _soundEngine.Play(StationManager.Previous());
            //    //        break;
            //    //    case AvailableActions.PlayerAction.Pause:
            //    //        _soundEngine.Pause(StationManager.PlayingStation);
            //    //        break;
            //    //    case AvailableActions.PlayerAction.Delete:
            //    //        StationManager.DeleteStation(_displayEngine.DeleteStation(StationManager.Stations));
            //    //        break;
            //    //    default:
            //    //        break;
            //    //}


            //} while (playerAction != AvailableActions.PlayerAction.Quit);
            //ApplicationDataHandler.Save(StationManager);
        }
    }
}
