using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GreenTree.Nachtragsmanagement.Core.Data;
using GreenTree.Nachtragsmanagement.Core.Domain.Misc;

namespace GreenTree.Nachtragsmanagement.Services.Misc
{
    public class MiscService : IMiscService
    {
        #region Fields

        private readonly IRepository<MailNotification> _mailNotificationRepository;
        private readonly IRepository<HelpPage> _helpPageRepository;

        #endregion

        #region Ctor

        /// <summary>
        /// Initializes a new instance of the MiscService class
        /// </summary>
        public MiscService(
            IRepository<MailNotification> mailNotificationRepository,
            IRepository<HelpPage> helpPageRepository)
        {
            _mailNotificationRepository = mailNotificationRepository;
            _helpPageRepository = helpPageRepository;
        }

        #endregion

        #region MailNotification

        /// <summary>
        /// Gets all mailNotifications
        /// </summary>
        public IList<MailNotification> GetAllMailNotifications()
        {
            return _mailNotificationRepository.Table.ToList();
        }

        /// <summary>
        /// Gets a mailNotification by specified Id
        /// </summary>
        /// <param name="id">MailNotification identifier.</param>
        public MailNotification GetMailNotificationById(int id)
        {
            return _mailNotificationRepository.GetById(id);
        }

        /// <summary>
        /// Gets all mailNotifications to the specified ids
        /// </summary>
        public IList<MailNotification> GetMailNotificationsByIds(int[] ids)
        {
            return _mailNotificationRepository.Table
                .Where(u => ids.Contains(u.Id))
                .ToList();
        }

        /// <summary>
        /// Insert a mailNotification
        /// </summary>
        /// <param name="mailNotification">MailNotification.</param>
        public void InsertMailNotification(MailNotification mailNotification)
        {
            _mailNotificationRepository.Insert(mailNotification);
        }

        /// <summary>
        /// Update a mailNotification
        /// </summary>
        /// <param name="mailNotification">MailNotification.</param>
        public void UpdateMailNotification(MailNotification mailNotification)
        {
            _mailNotificationRepository.Update(mailNotification);
        }

        /// <summary>
        /// Delete a mailNotification
        /// </summary>
        /// <param name="mailNotification">MailNotification.</param>
        public void DeleteMailNotification(MailNotification mailNotification)
        {
            _mailNotificationRepository.Delete(mailNotification);
        }

        #endregion

        #region HelpPage

        /// <summary>
        /// Gets all helpPages
        /// </summary>
        public IList<HelpPage> GetAllHelpPages()
        {
            return _helpPageRepository.Table.ToList();
        }

        /// <summary>
        /// Gets all helpPages without actual content
        /// </summary>
        public IList<HelpPage> GetAllHelpPagesWithoutContent()
        {
            return _helpPageRepository.Table
                .ToList()
                .Select(u => new HelpPage
                {
                    Id = u.Id,
                    Children = u.Children,
                    DisplayIndex = u.DisplayIndex,
                    Parent = u.Parent,
                    ParentId = u.ParentId,
                    Title = u.Title
                })
                .ToList();
        }

        /// <summary>
        /// Gets a helpPage by specified Id
        /// </summary>
        /// <param name="id">HelpPage identifier.</param>
        public HelpPage GetHelpPageById(int id)
        {
            return _helpPageRepository.GetById(id);
        }

        /// <summary>
        /// Gets all helpPages to the specified ids
        /// </summary>
        public IList<HelpPage> GetHelpPagesByIds(int[] ids)
        {
            return _helpPageRepository.Table
                .Where(u => ids.Contains(u.Id))
                .ToList();
        }

        /// <summary>
        /// Insert a helpPage
        /// </summary>
        /// <param name="helpPage">HelpPage.</param>
        public void InsertHelpPage(HelpPage helpPage)
        {
            _helpPageRepository.Insert(helpPage);
        }

        /// <summary>
        /// Update a helpPage
        /// </summary>
        /// <param name="helpPage">HelpPage.</param>
        public void UpdateHelpPage(HelpPage helpPage)
        {
            _helpPageRepository.Update(helpPage);
        }

        /// <summary>
        /// Delete a helpPage
        /// </summary>
        /// <param name="helpPage">HelpPage.</param>
        public void DeleteHelpPage(HelpPage helpPage)
        {
            _helpPageRepository.Delete(helpPage);
        }

        #endregion
    }
}