/*
 * Copyright 2016 Ecole des Mines de Saint-Etienne.
 *
 * 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 org.etsi.saref.server;

import java.util.HashMap;
import org.etsi.saref.server.entities.MediaTypeExt;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.Variant;
import org.apache.jena.shared.PrefixMapping;
import org.apache.jena.shared.impl.PrefixMappingImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Maxime Lefrançois <maxime.lefrancois at emse.fr>
 */
public class Utils{

    public static final String NS = "https://saref.etsi.org/";
    public static final String DS = "http://localhost:3030/ds/";
    public static final String CONFIG = "http://example.org/" + "config";

    private static final Logger LOG = LoggerFactory.getLogger(Utils.class);

    public static final MediaTypeExt TEXT_HTML = new MediaTypeExt("text", "html", "html", null, false);
    public static final MediaTypeExt APPLICATION_RDFXML = new MediaTypeExt("application", "rdf+xml", "rdf", "RDF/XML", true);
    public static final MediaTypeExt TEXT_TURTLE = new MediaTypeExt("text", "turtle", "ttl", "TTL", true);
    public static final MediaTypeExt APPLICATION_NTRIPLE = new MediaTypeExt("application", "n-triples", "nt", "N-TRIPLE", true);
    public static final MediaTypeExt APPLICATION_N3 = new MediaTypeExt("application", "n3", "n3", "N3", true);
    public static final MediaTypeExt APPLICATION_JSONLD = new MediaTypeExt("application", "ld+json", "jsonld", "JSON-LD", true);
    public static final MediaTypeExt APPLICATION_XHTMLXML = new MediaTypeExt("application", "xhtml+xml", "html", null, false);

    public static final List<Variant> VARIANTS = Variant.mediaTypes(
            TEXT_HTML,
            APPLICATION_RDFXML,
            TEXT_TURTLE,
            APPLICATION_NTRIPLE,
            APPLICATION_N3,
            APPLICATION_JSONLD,
            APPLICATION_XHTMLXML).build();

    public static final Map<String, MediaTypeExt> EXTENSIONS;

    static {
        EXTENSIONS = new HashMap<>();
        for (Variant variant : VARIANTS) {
            MediaTypeExt mt = (MediaTypeExt) variant.getMediaType();
            EXTENSIONS.put(mt.getExt(), mt);
        }
    }

    public static final PrefixMapping PM = new PrefixMappingImpl();

    static {
        PM.setNsPrefix("owl", "http://www.w3.org/2002/07/owl#");
        PM.setNsPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
        PM.setNsPrefix("xml", "http://www.w3.org/XML/1998/namespace");
        PM.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#");
        PM.setNsPrefix("foaf", "http://xmlns.com/foaf/0.1/");
        PM.setNsPrefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
        PM.setNsPrefix("vann", "http://purl.org/vocab/vann/");
        PM.setNsPrefix("voaf", "http://purl.org/vocommons/voaf#");
        PM.setNsPrefix("dcterms", "http://purl.org/dc/terms/");
        PM.setNsPrefix("saref", "https://saref.etsi.org/core/");
    }

}
