// This file is auto-generated by alef. DO NOT EDIT.
// alef:hash:4e15143f4af1ae8bafbdb1506ef057da924484c66a19483966333558ad437e75
#nullable enable

using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Kreuzberg;
/// <summary>
/// Text direction enumeration for HTML documents.
/// </summary>
[JsonConverter(typeof(TextDirectionJsonConverter))]
public enum TextDirection
{
    /// <summary>
    /// Left-to-right text direction
    /// </summary>
    [JsonPropertyName("ltr")]
    LeftToRight,
    /// <summary>
    /// Right-to-left text direction
    /// </summary>
    [JsonPropertyName("rtl")]
    RightToLeft,
    /// <summary>
    /// Automatic text direction detection
    /// </summary>
    [JsonPropertyName("auto")]
    Auto,
}


/// <summary>
/// Custom JSON converter for <see cref="TextDirection"/> that respects explicit variant names.
/// </summary>
internal sealed class TextDirectionJsonConverter : JsonConverter<TextDirection>
{
    public override TextDirection Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var value = reader.GetString();
        return value switch
        {
            "ltr" => TextDirection.LeftToRight,
            "rtl" => TextDirection.RightToLeft,
            "auto" => TextDirection.Auto,
            _ => throw new JsonException($"Unknown TextDirection value: {value}")
        };
    }

    public override void Write(Utf8JsonWriter writer, TextDirection value, JsonSerializerOptions options)
    {
        var str = value switch
        {
            TextDirection.LeftToRight => "ltr",
            TextDirection.RightToLeft => "rtl",
            TextDirection.Auto => "auto",
            _ => throw new JsonException($"Unknown TextDirection value: {value}")
        };
        writer.WriteStringValue(str);
    }
}
