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

namespace eagle {
    using HeroId = Int32;
    using ProvinceId = Int32;

    public class TrainCommandSelector : CommandSelector {
        public HeroDropdownController heroDropdownController;

        public override AvailableCommand.SealedValueOneofCase CommandType =>
                AvailableCommand.SealedValueOneofCase.TrainCommand;
        public override string HeaderString => "Train";
        public override string CommitButtonString => "Commit Train";

        public override List<HeroId> TargetedHeroIds => new List<HeroId> { SelectedHeroId };
        public override bool HeroIsTargetable(HeroId heroId) =>
                TrainAvailableCommand.AvailableHeroIds.Contains(heroId);
        public override void AddTargetedHero(HeroId heroId) =>
                heroDropdownController.SelectedHeroId = heroId;

        private HeroId SelectedHeroId => heroDropdownController.SelectedHeroId;

        private TrainAvailableCommand TrainAvailableCommand => _availableCommand.TrainCommand;
        private ProvinceId ActingProvinceId => TrainAvailableCommand.ActingProvinceId;

        protected override void SetUpUI() {
            var heroes =
                    TrainAvailableCommand.AvailableHeroIds.Select(id => _model.Heroes[id]).ToList();
            heroDropdownController.AvailableHeroes = heroes;

            heroDropdownController.SelectedHeroId = TrainAvailableCommand.RecommendedHeroId;
        }

        public override SelectedCommand Command =>
                new() { TrainCommand = new TrainSelectedCommand { ActingHeroId = SelectedHeroId } };
    }
}