using System.Collections.Generic;
using System.Linq;
using Toolbox.Docking.Api.Control;
using Toolbox.Docking.Api.Objects.Profiler;

namespace ToolboxAddinExamples.Profiler
{
    public class ProfilerAddin : ITbProfiler
    {
        private readonly IReadOnlyDictionary<string, string> _atomCategoryMatrix;
        
        public const string DefaultCategory = "No Oxygen, Nitrogen or Sulfur";

        public ProfilerAddin(IReadOnlyDictionary<string, string> atomCategoryMatrix)
        {
            _atomCategoryMatrix = atomCategoryMatrix;
        }

        public void Dispose()
        {
            // Nothing to dispose
        }

        public string GetOptions() => string.Empty;

        public void SetOptions(string newOptions)
        {
            //do nothing
        }

        public IEnumerable<string> GetCategoriesOf(ITbBasket target)
        {
            var categories = new List<string>();
            var searchSmi = target.Chemical.Smiles.ToUpper();

            foreach (var categoryPair in _atomCategoryMatrix)
            {
                if (searchSmi.Contains(categoryPair.Key))
                    categories.Add(categoryPair.Value);
            }

            if (!categories.Any())
                categories.Add(DefaultCategory);

            return categories;
        }
    }
}
