{{ self::swift_doc_block(doc, "") }}public enum {{ class_name }}: Hashable, Equatable, Sendable{% if is_error %}, Error{% endif %} {
{%- for variant in variants %}
{%- if variant.is_unit() %}
{{ self::swift_doc_block(variant.doc, "    ") }}    case {{ variant.swift_name }}
{%- elif variant.is_single_tuple() %}
{{ self::swift_doc_block(variant.doc, "    ") }}    case {{ variant.swift_name }}({{ variant.fields()[0].swift_type }})
{%- else %}
{{ self::swift_doc_block(variant.doc, "    ") }}    case {{ variant.swift_name }}({% for field in variant.fields() %}{{ field.swift_name }}: {{ field.swift_type }}{% if !loop.last %}, {% endif %}{% endfor %})
{%- endif %}
{%- endfor %}

}

extension {{ class_name }}: WireCodable {
    @inlinable static func decode(from reader: inout WireReader) -> {{ class_name }} {
        let tag = reader.readI32()
        switch tag {
{%- for variant in variants %}
        case {{ variant.discriminant }}:
{%- if variant.is_unit() %}
            return .{{ variant.swift_name }}
{%- elif variant.is_single_tuple() %}
            return .{{ variant.swift_name }}({{ variant.tuple_value_reader_decode() }})
{%- else %}
            return .{{ variant.swift_name }}({% for field in variant.fields() %}{{ field.swift_name }}: {{ field.wire_reader_decode() }}{% if !loop.last %}, {% endif %}{% endfor %})
{%- endif %}
{%- endfor %}
        default:
            fatalError("Invalid {{ class_name }} tag: \(tag)")
        }
    }

    @inlinable func encode(to writer: inout WireWriter) {
        switch self {
{%- for variant in variants %}
{%- if variant.is_unit() %}
        case .{{ variant.swift_name }}:
            writer.writeI32({{ variant.discriminant }})
{%- elif variant.is_single_tuple() %}
        case let .{{ variant.swift_name }}(value):
            writer.writeI32({{ variant.discriminant }})
            {{ variant.tuple_value_writer_encode() }}
{%- else %}
        case let .{{ variant.swift_name }}({% for field in variant.fields() %}{{ field.swift_name }}{% if !loop.last %}, {% endif %}{% endfor %}):
            writer.writeI32({{ variant.discriminant }})
{%- for field in variant.fields() %}
            {{ field.wire_writer_encode() }}
{%- endfor %}
{%- endif %}
{%- endfor %}
        }
    }
}
