using ZelWiki.Engine.Library;
using ZelWiki.Engine.Library.Interfaces;
using ZelWiki.Library.Interfaces;

namespace ZelWiki.Engine
{
    public class ZelEngine : IZelEngine
    {
        public IScopeFunctionHandler ScopeFunctionHandler { get; private set; }
        public IStandardFunctionHandler StandardFunctionHandler { get; private set; }
        public IProcessingInstructionFunctionHandler ProcessingInstructionFunctionHandler { get; private set; }
        public IPostProcessingFunctionHandler PostProcessingFunctionHandler { get; private set; }
        public IMarkupHandler MarkupHandler { get; private set; }
        public IHeadingHandler HeadingHandler { get; private set; }
        public ICommentHandler CommentHandler { get; private set; }
        public IEmojiHandler EmojiHandler { get; private set; }
        public IExternalLinkHandler ExternalLinkHandler { get; private set; }
        public IInternalLinkHandler InternalLinkHandler { get; private set; }
        public IExceptionHandler ExceptionHandler { get; private set; }
        public ICompletionHandler CompletionHandler { get; private set; }

        public ZelEngine(
            IStandardFunctionHandler standardFunctionHandler,
            IScopeFunctionHandler scopeFunctionHandler,
            IProcessingInstructionFunctionHandler processingInstructionFunctionHandler,
            IPostProcessingFunctionHandler postProcessingFunctionHandler,
            IMarkupHandler markupHandler,
            IHeadingHandler headingHandler,
            ICommentHandler commentHandler,
            IEmojiHandler emojiHandler,
            IExternalLinkHandler externalLinkHandler,
            IInternalLinkHandler internalLinkHandler,
            IExceptionHandler exceptionHandler,
            ICompletionHandler completionHandler)
        {
            StandardFunctionHandler = standardFunctionHandler;

            StandardFunctionHandler = standardFunctionHandler;
            ScopeFunctionHandler = scopeFunctionHandler;
            ProcessingInstructionFunctionHandler = processingInstructionFunctionHandler;
            PostProcessingFunctionHandler = postProcessingFunctionHandler;
            MarkupHandler = markupHandler;
            HeadingHandler = headingHandler;
            CommentHandler = commentHandler;
            EmojiHandler = emojiHandler;
            ExternalLinkHandler = externalLinkHandler;
            InternalLinkHandler = internalLinkHandler;
            ExceptionHandler = exceptionHandler;
            CompletionHandler = completionHandler;
        }

        /// <summary>
        /// Transforms the content for the given page.
        /// </summary>
        /// <param name="session">The users current state, used for localization.</param>
        /// <param name="page">The page that is being processed.</param>
        /// <param name="revision">The revision of the page that is being processed.</param>
        /// <param name="omitMatches">The type of matches that we want to omit from processing.</param>
        /// <returns></returns>
        public IZelEngineState Transform(ISessionState? session, IPage page, int? revision = null, Constants.WikiMatchType[]? omitMatches = null)
            => new ZelEngineState(this, session, page, revision, omitMatches).Transform();
    }
}
