/*
 * Copyright (C) 2017 Reece H. Dunn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.co.reecedunn.intellij.plugin.marklogic.query;

import uk.co.reecedunn.intellij.plugin.marklogic.query.options.EvalOptionsBuilder;
import uk.co.reecedunn.intellij.plugin.marklogic.query.options.OptionsBuilder;
import uk.co.reecedunn.intellij.plugin.marklogic.query.vars.KeyValueVarsBuilder;
import uk.co.reecedunn.intellij.plugin.marklogic.query.vars.MapVarsBuilder;
import uk.co.reecedunn.intellij.plugin.marklogic.query.vars.VarsBuilder;

public enum Function {
    DBG_EVAL_50(
        "dbg:eval($query, $vars, $options)",
        KeyValueVarsBuilder.INSTANCE,
        EvalOptionsBuilder.INSTANCE),
    DBG_EVAL_80(
        "dbg:eval($query, $vars, $options)",
        MapVarsBuilder.INSTANCE,
        EvalOptionsBuilder.INSTANCE),

    DBG_INVOKE_50(
        "dbg:invoke($path, $vars, $options)",
        KeyValueVarsBuilder.INSTANCE,
        EvalOptionsBuilder.INSTANCE),
    DBG_INVOKE_80(
        "dbg:invoke($path, $vars, $options)",
        MapVarsBuilder.INSTANCE,
        EvalOptionsBuilder.INSTANCE),

    PROF_EVAL_50(
        "prof:eval($query, $vars, $options)",
        KeyValueVarsBuilder.INSTANCE,
        EvalOptionsBuilder.INSTANCE),
    PROF_EVAL_80(
        "prof:eval($query, $vars, $options)",
        MapVarsBuilder.INSTANCE,
        EvalOptionsBuilder.INSTANCE),

    PROF_INVOKE_50(
        "prof:invoke($path, $vars, $options)",
        KeyValueVarsBuilder.INSTANCE,
        EvalOptionsBuilder.INSTANCE),
    PROF_INVOKE_80(
        "prof:invoke($path, $vars, $options)",
        MapVarsBuilder.INSTANCE,
        EvalOptionsBuilder.INSTANCE),

    PROF_XSLT_EVAL_50(
            "prof:xslt-eval($query, $input, $vars, $options)",
            MapVarsBuilder.INSTANCE,
            EvalOptionsBuilder.INSTANCE),
    PROF_XSLT_INVOKE_50(
            "prof:xslt-invoke($path, $input, $vars, $options)",
            MapVarsBuilder.INSTANCE,
            EvalOptionsBuilder.INSTANCE),

    SEM_SPARQL_70(
        "sem:sparql($query, $vars)",
        MapVarsBuilder.INSTANCE,
        null),

    SEM_SPARQL_UPDATE_80(
            "sem:sparql-update($query, $vars)",
            MapVarsBuilder.INSTANCE,
            null),

    XDMP_EVAL_50(
        "xdmp:eval($query, $vars, $options)",
        KeyValueVarsBuilder.INSTANCE,
        EvalOptionsBuilder.INSTANCE),
    XDMP_EVAL_70(
        "xdmp:eval($query, $vars, $options)",
        MapVarsBuilder.INSTANCE,
        EvalOptionsBuilder.INSTANCE),

    XDMP_INVOKE_50(
        "xdmp:invoke($path, $vars, $options)",
        KeyValueVarsBuilder.INSTANCE,
        EvalOptionsBuilder.INSTANCE),
    XDMP_INVOKE_70(
        "xdmp:invoke($path, $vars, $options)",
        MapVarsBuilder.INSTANCE,
        EvalOptionsBuilder.INSTANCE),

    XDMP_JAVASCRIPT_EVAL_80(
        "xdmp:javascript-eval($query, $vars, $options)",
        MapVarsBuilder.INSTANCE,
        EvalOptionsBuilder.INSTANCE),

    XDMP_SQL_80(
        "xdmp:sql($query)",
        null,
        null),
    XDMP_SQL_90(
        "xdmp:sql($query, (), $vars)",
        MapVarsBuilder.INSTANCE,
        null),

    XDMP_XSLT_EVAL_50(
            "xdmp:xslt-eval($query, $input, $vars, $options)",
            MapVarsBuilder.INSTANCE,
            EvalOptionsBuilder.INSTANCE),
    XDMP_XSLT_INVOKE_50(
            "xdmp:xslt-invoke($path, $input, $vars, $options)",
            MapVarsBuilder.INSTANCE,
            EvalOptionsBuilder.INSTANCE);

    private final String function;
    private final VarsBuilder varsBuilder;
    private final OptionsBuilder optionsBuilder;

    Function(String function, VarsBuilder varsBuilder, OptionsBuilder optionsBuilder) {
        this.function = function;
        this.varsBuilder = varsBuilder;
        this.optionsBuilder = optionsBuilder;
    }

    public String getFunction() {
        return function;
    }

    public VarsBuilder getVarsBuilder() {
        return varsBuilder;
    }

    public OptionsBuilder getOptionsBuilder() {
        return optionsBuilder;
    }
}

@@ -2326,35 +2326,53 @@
 Builder.INSTANCE
+,%0A            true
 ),%0A
-
     PROF_XSLT_IN
@@ -2512,32 +2512,50 @@
 Builder.INSTANCE
+,%0A            true
 ),%0A%0A    SEM_SPAR
@@ -3827,32 +3827,50 @@
 Builder.INSTANCE
+,%0A            true
 ),%0A    XDMP_XSLT
@@ -4021,16 +4021,34 @@
 INSTANCE
+,%0A            true
 );%0A%0A    
@@ -4169,16 +4169,56 @@
 Builder;
+%0A    private final boolean isStylesheet;
 %0A%0A    Fu
@@ -4295,24 +4295,201 @@
 sBuilder) %7B%0A
+        this(function, varsBuilder, optionsBuilder, false);%0A    %7D%0A%0A    Function(String function, VarsBuilder varsBuilder, OptionsBuilder optionsBuilder, boolean isStylesheet) %7B%0A
         this
@@ -4588,32 +4588,74 @@
 optionsBuilder;%0A
+        this.isStylesheet = isStylesheet;%0A
     %7D%0A%0A    publi
@@ -4828,32 +4828,32 @@
 ionsBuilder() %7B%0A
-
         return o
@@ -4872,11 +4872,88 @@
 r;%0A    %7D
+%0A%0A    public boolean isStylesheetQuery() %7B%0A        return isStylesheet;%0A    %7D
 %0A%7D%0A

Add isStylesheetQuery to Function, to identify xslt-based queries.