// Auto-generated by BoltFFI. Do not edit.
package {{ package_name }};

{{ self::javadoc_block(enumeration.doc, "") }}public sealed interface {{ enumeration.class_name }} permits {% for variant in enumeration.variants %}{{ enumeration.class_name }}.{{ variant.name }}{% if !loop.last %}, {% endif %}{% endfor %} {
{%- for variant in enumeration.variants %}
{%- if variant.is_unit() %}

{{ self::javadoc_block(variant.doc, "    ") }}    record {{ variant.name }}() implements {{ enumeration.class_name }} {}
{%- else %}

{{ self::javadoc_block(variant.doc, "    ") }}    record {{ variant.name }}({% for field in variant.fields %}{{ field.java_type }} {{ field.name }}{% if !loop.last %}, {% endif %}{% endfor %}) implements {{ enumeration.class_name }} {}
{%- endif %}
{%- endfor %}

{%- for ctor in enumeration.constructors %}
{% include "render_java/value_type_constructor.txt" %}
{%- endfor %}

{%- for method in enumeration.methods %}
{% include "render_java/value_type_method.txt" %}
{%- endfor %}

    static {{ enumeration.class_name }} decode(WireReader reader) {
        int tag = reader.readI32();
        return switch (tag) {
{%- for variant in enumeration.variants %}
{%- if variant.is_unit() %}
            case {{ variant.tag }} -> new {{ variant.name }}();
{%- else %}
            case {{ variant.tag }} -> new {{ variant.name }}(
{%- for field in variant.fields %}
                {{ field.wire_decode_expr }}{% if !loop.last %},{% endif %}
{%- endfor %}
            );
{%- endif %}
{%- endfor %}
            default -> throw new RuntimeException("Unknown {{ enumeration.class_name }} tag: " + tag);
        };
    }

    default int wireEncodedSize() {
        return 4 + switch (this) {
{%- for variant in enumeration.variants %}
{%- if variant.is_unit() %}
            case {{ variant.name }} _v -> 0;
{%- else %}
            case {{ variant.name }} _v -> {% for field in variant.fields %}{{ field.wire_size_expr }}{% if !loop.last %} + {% endif %}{% endfor %};
{%- endif %}
{%- endfor %}
        };
    }

    default void wireEncodeTo(WireWriter wire) {
        switch (this) {
{%- for variant in enumeration.variants %}
{%- if variant.is_unit() %}
            case {{ variant.name }} _v -> wire.writeI32({{ variant.tag }});
{%- else %}
            case {{ variant.name }} _v -> {
                wire.writeI32({{ variant.tag }});
{%- for field in variant.fields %}
                {{ field.wire_encode_expr }};
{%- endfor %}
            }
{%- endif %}
{%- endfor %}
        }
    }
}
