/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF 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.
 */
package org.apache.tinkerpop.gremlin.driver.ser;

import org.apache.tinkerpop.gremlin.driver.MessageSerializer;

/**
 * An enum of the default serializers.
 *
 * @author Stephen Mallette (http://stephen.genoprime.com)
 */
public enum Serializers {

    /**
     * GraphSON 3.0.
     */
    GRAPHSON(SerTokens.MIME_JSON),

    /**
     * GraphSON 1.0 with types.
     */
    GRAPHSON_V1D0(SerTokens.MIME_GRAPHSON_V1D0),

    /**
     * GraphSON 2.0 without types.
     */
    GRAPHSON_V1D0_UNTYPED(SerTokens.MIME_GRAPHSON_V1D0_UNTYPED),

    /**
     * GraphSON 2.0 with types.
     */
    GRAPHSON_V2D0(SerTokens.MIME_GRAPHSON_V2D0),

    /**
     * GraphSON 2.0 without types.
     */
    GRAPHSON_V2D0_UNTYPED(SerTokens.MIME_GRAPHSON_V2D0_UNTYPED),

    /**
     * GraphSON 3.0 with types.
     */
    GRAPHSON_V3D0(SerTokens.MIME_GRAPHSON_V3D0),
    GRAPHBINARY_V1D0(SerTokens.MIME_GRAPHBINARY_V1D0);

    private String value;

    Serializers(final String mimeType) {
        this.value = mimeType;
    }

    public String getValue() {
        return value;
    }

    public MessageSerializer<?> simpleInstance() {
        switch (value) {
            case SerTokens.MIME_JSON:
            case SerTokens.MIME_GRAPHSON_V3D0:
                return new GraphSONMessageSerializerV3d0();
            case SerTokens.MIME_GRAPHSON_V1D0:
                return new GraphSONMessageSerializerGremlinV1d0();
            case SerTokens.MIME_GRAPHSON_V1D0_UNTYPED:
                return new GraphSONUntypedMessageSerializerV1d0();
            case SerTokens.MIME_GRAPHSON_V2D0:
                return new GraphSONMessageSerializerV2d0();
            case SerTokens.MIME_GRAPHSON_V2D0_UNTYPED:
                return new GraphSONUntypedMessageSerializerV2d0();
            case SerTokens.MIME_GRAPHBINARY_V1D0:
                return new GraphBinaryMessageSerializerV1();
            default:
                throw new RuntimeException("Could not create a simple MessageSerializer instance of " + value);
        }
    }
}
