using System;
using System.Collections.Generic;
using System.Linq;
using Net.Eagle0.Eagle.Api;
using Net.Eagle0.Eagle.Views;

namespace eagle {
    using HeroId = Int32;

    public class ExileVassalCommandSelector : CommandSelector {
        // Unity accessors
        public HeroDropdownController heroSelectionDropdownController;

        public HeroDetailsController heroDetails;

        public override AvailableCommand.SealedValueOneofCase CommandType =>
                AvailableCommand.SealedValueOneofCase.ExileVassalCommand;
        public override string HeaderString => "Exile Vassal";
        public override string CommitButtonString => $"Commit Exile";

        private HeroId SelectedHeroId => heroSelectionDropdownController.SelectedHeroId;
        public HeroView SelectedHero => _model.Heroes[SelectedHeroId];

        public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedHeroId };
        public override bool HeroIsTargetable(HeroId heroId) =>
                ExileVassalAvailableCommand.ExilableHeroIds.Contains(heroId);
        public override void AddTargetedHero(HeroId heroId) =>
                heroSelectionDropdownController.SelectedHeroId = heroId;

        private ExileVassalAvailableCommand ExileVassalAvailableCommand =>
                _availableCommand.ExileVassalCommand;

        protected override void SetUpUI() {
            heroSelectionDropdownController.AvailableHeroes =
                    ExileVassalAvailableCommand.ExilableHeroIds.Select(hid => _model.Heroes[hid])
                            .ToList();
            heroSelectionDropdownController.SelectedHeroIdUpdated = () => DisplaySelectedHero();
            DisplaySelectedHero();
        }

        public override SelectedCommand Command => new() {
            ExileVassalCommand = new ExileVassalSelectedCommand { ExiledHeroId = SelectedHeroId }
        };

        public void DropdownSelected(int value) { DisplaySelectedHero(); }

        private void DisplaySelectedHero() { heroDetails.SetHero(SelectedHero, _model); }
    }
}
