
/// <summary>Custom JSON converter for <see cref="{{ enum_pascal }}"/> that respects explicit variant names.</summary>
internal sealed class {{ enum_pascal }}JsonConverter : JsonConverter<{{ enum_pascal }}>
{
    public override {{ enum_pascal }} Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var value = reader.GetString();
        return value switch
        {
{%- for variant in variants %}
            "{{ variant.json_name }}" => {{ enum_pascal }}.{{ variant.pascal_name }},
{%- endfor %}
            _ => throw new JsonException($"Unknown {{ enum_pascal }} value: {value}")
        };
    }

    public override void Write(Utf8JsonWriter writer, {{ enum_pascal }} value, JsonSerializerOptions options)
    {
        var str = value switch
        {
{%- for variant in variants %}
            {{ enum_pascal }}.{{ variant.pascal_name }} => "{{ variant.json_name }}",
{%- endfor %}
            _ => throw new JsonException($"Unknown {{ enum_pascal }} value: {value}")
        };
        writer.WriteStringValue(str);
    }
}
