/*
 * Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
 * license agreements.  See the NOTICE file distributed with this work for
 * additional information regarding copyright ownership.  Crate licenses
 * this file to you 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.
 *
 * However, if you have executed another commercial license agreement
 * with Crate these terms will supersede the license and you may use the
 * software solely pursuant to the terms of the relevant commercial agreement.
 */

package io.crate.analyze;

import io.crate.expression.symbol.Symbol;
import io.crate.sql.tree.GenericProperties;
import io.crate.common.collections.Tuple;

import javax.annotation.Nullable;
import java.util.Map;

public class AnalyzedCreateAnalyzer implements DDLStatement {

    private final String ident;
    @Nullable
    private final String extendedAnalyzerName;
    @Nullable
    private final Tuple<String, GenericProperties<Symbol>> tokenizer;
    private final GenericProperties<Symbol> genericAnalyzerProperties;
    private final Map<String, GenericProperties<Symbol>> charFilters;
    private final Map<String, GenericProperties<Symbol>> tokenFilters;

    AnalyzedCreateAnalyzer(String ident,
                           @Nullable String extendedAnalyzerName,
                           @Nullable Tuple<String, GenericProperties<Symbol>> tokenizer,
                           GenericProperties<Symbol> genericAnalyzerProperties,
                           Map<String, GenericProperties<Symbol>> tokenFilters,
                           Map<String, GenericProperties<Symbol>> charFilters) {
        this.ident = ident;
        this.extendedAnalyzerName = extendedAnalyzerName;
        this.tokenizer = tokenizer;
        this.genericAnalyzerProperties = genericAnalyzerProperties;
        this.tokenFilters = tokenFilters;
        this.charFilters = charFilters;
    }

    public String ident() {
        return ident;
    }

    @Nullable
    public String extendedAnalyzerName() {
        return extendedAnalyzerName;
    }

    @Nullable
    public Tuple<String, GenericProperties<Symbol>> tokenizer() {
        return tokenizer;
    }

    public Map<String, GenericProperties<Symbol>> charFilters() {
        return charFilters;
    }

    public Map<String, GenericProperties<Symbol>> tokenFilters() {
        return tokenFilters;
    }

    public GenericProperties<Symbol> genericAnalyzerProperties() {
        return genericAnalyzerProperties;
    }

    @Override
    public <C, R> R accept(AnalyzedStatementVisitor<C, R> analyzedStatementVisitor, C context) {
        return analyzedStatementVisitor.visitCreateAnalyzerStatement(this, context);
    }
}

@@ -1224,16 +1224,52 @@
 til.Map;
+%0Aimport java.util.function.Consumer;
 %0A%0Apublic
@@ -3223,11 +3223,457 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public void visitSymbols(Consumer%3C? super Symbol%3E consumer) %7B%0A        if (tokenizer != null) %7B%0A            tokenizer.v2().properties().values().forEach(consumer);%0A        %7D%0A        tokenFilters.values().forEach(x -%3E x.properties().values().forEach(consumer));%0A        charFilters.values().forEach(x -%3E x.properties().values().forEach(consumer));%0A        genericAnalyzerProperties.properties().values().forEach(consumer);%0A    %7D
 %0A%7D%0A

Fix flaky CommonAnalyzerITest / add visitSymbols to create analyzer stmt