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

namespace BokBonCheck
{
    public class BookSearchResult
    {
        public string SiteName { get; set; }
        public int BookCount { get; set; }
        public string SearchTerm { get; set; }
        public DateTime SearchTime { get; set; }
        public string ErrorMessage { get; set; }
        public bool IsSuccess { get; set; }

        public string Resulthtml { get; set; }
    }

    public class BookSearchService
    {
        private readonly List<ILibrarySearcher> _searchers;

        public BookSearchService()
        {
            _searchers = new List<ILibrarySearcher>
            {
            };
        }


        /// <summary>
        /// Return Searcher
        /// </summary>
        /// <param name="no"></param>
        /// <returns></returns>
        public ILibrarySearcher Get(int no)
        {
            return _searchers.Where(t => t.No == no).FirstOrDefault();
        }

        public ILibrarySearcher Get(string no)
        {
            return _searchers.Where(t => t.SiteName == no).FirstOrDefault();
        }

        public void AddSearcher(ILibrarySearcher searcher)
        {
            if (!_searchers.Any(s => s.SiteName == searcher.SiteName))
            {
                _searchers.Add(searcher);
            }
        }

        public void RemoveSearcher(string siteName)
        {
            var searcher = _searchers.FirstOrDefault(s => s.SiteName == siteName);
            if (searcher != null)
            {
                _searchers.Remove(searcher);
            }
        }

        public List<string> GetAvailableSites()
        {
            return _searchers.Select(s => s.SiteName).ToList();
        }

        public void ClearSearchers()
        {
            _searchers.Clear();
        }

        
    }
}