package com.yangdb.fuse.asg.translator.sparql;

/*-
 * #%L
 * fuse-model
 * %%
 * Copyright (C) 2016 - 2020 The YangDb Graph Database Project
 * %%
 * 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.
 * #L%
 */

import com.google.inject.Inject;
import com.yangdb.fuse.asg.translator.sparql.SparqlTranslator;
import com.yangdb.fuse.dispatcher.query.QueryTransformer;
import com.yangdb.fuse.model.asgQuery.AsgQuery;
import com.yangdb.fuse.model.query.QueryInfo;
import com.yangdb.fuse.model.transport.CreateQueryRequestMetadata;

import java.util.function.Function;

import static com.yangdb.fuse.model.transport.CreateQueryRequestMetadata.QueryLanguage.cypher;
import static com.yangdb.fuse.model.transport.CreateQueryRequestMetadata.QueryLanguage.sparql;

public class AsgSparQLTransformer implements QueryTransformer<QueryInfo<String>, AsgQuery>, Function<QueryInfo<String>,Boolean> {
    public static final String transformerName = "AsgSparQLTransformer.@transformer";

    private SparqlTranslator translator;


    @Inject
    public AsgSparQLTransformer(SparqlTranslator translator) {
        this.translator = translator;
    }

    /**
     * transform Spqrql to V1 query
     *
     * @param query
     * @return
     */
    public AsgQuery transform(QueryInfo<String> query) {
        return translator.translate(query);
    }

    @Override
    public Boolean apply(QueryInfo<String> queryInfo) {
        return sparql.name().equalsIgnoreCase(queryInfo.getQueryType());
    }

}
