<%
  const type = locals.type;
  const properties = locals.properties;
-%>
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`.

#include "<%- type.replace('-', '_') %>_layer.hpp"

#include <string>

#include "../conversion/property_value.hpp"

namespace mbgl {
namespace android {

<% if (type === 'background') { -%>
    <%- camelize(type) %>Layer::<%- camelize(type) %>Layer(jni::JNIEnv& env, jni::String layerId)
        : Layer(env, std::make_unique<mbgl::style::<%- camelize(type) %>Layer>(jni::Make<std::string>(env, layerId))) {
<% } else { -%>
    <%- camelize(type) %>Layer::<%- camelize(type) %>Layer(jni::JNIEnv& env, jni::String layerId, jni::String sourceId)
        : Layer(env, std::make_unique<mbgl::style::<%- camelize(type) %>Layer>(jni::Make<std::string>(env, layerId), jni::Make<std::string>(env, sourceId))) {
<% } -%>
    }

    <%- camelize(type) %>Layer::<%- camelize(type) %>Layer(mbgl::Map& map, mbgl::style::<%- camelize(type) %>Layer& coreLayer)
        : Layer(map, coreLayer) {
    }

    <%- camelize(type) %>Layer::~<%- camelize(type) %>Layer() = default;

    // Property getters

<% for (const property of properties) { -%>
    jni::Object<jni::ObjectTag> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>(jni::JNIEnv& env) {
        using namespace mbgl::android::conversion;
        Result<jni::jobject*> converted = convert<jni::jobject*>(env, layer.as<mbgl::style::<%- camelize(type) %>Layer>()-><%- camelize(type) %>Layer::get<%- camelize(property.name) %>());
        return jni::Object<jni::ObjectTag>(*converted);
    }

<% } -%>
    jni::Class<<%- camelize(type) %>Layer> <%- camelize(type) %>Layer::javaClass;

    jni::jobject* <%- camelize(type) %>Layer::createJavaPeer(jni::JNIEnv& env) {
        static auto constructor = <%- camelize(type) %>Layer::javaClass.template GetConstructor<jni::jlong>(env);
        return <%- camelize(type) %>Layer::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
    }

    void <%- camelize(type) %>Layer::registerNative(jni::JNIEnv& env) {
        //Lookup the class
        <%- camelize(type) %>Layer::javaClass = *jni::Class<<%- camelize(type) %>Layer>::Find(env).NewGlobalRef(env).release();

        #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)

        //Register the peer
        jni::RegisterNativePeer<<%- camelize(type) %>Layer>(
            env, <%- camelize(type) %>Layer::javaClass, "nativePtr",
<% if (type === 'background') { -%>
            std::make_unique<<%- camelize(type) %>Layer, JNIEnv&, jni::String>,
<% } else { -%>
            std::make_unique<<%- camelize(type) %>Layer, JNIEnv&, jni::String, jni::String>,
<% } -%>
            "initialize",
            "finalize",<% for(var i = 0; i < properties.length; i++) {%>
            METHOD(&<%- camelize(type) %>Layer::get<%- camelize(properties[i].name) %>, "nativeGet<%- camelize(properties[i].name) %>")<% if(i != (properties.length -1)) {-%>,<% } -%>
<% } -%>);
    }

} // namespace android
} // namespace mbgl
