// 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>
/// Page Segmentation Mode for Tesseract OCR
/// </summary>
[JsonConverter(typeof(PSMModeJsonConverter))]
public enum PSMMode
{
    [JsonPropertyName("osdonly")]
    OsdOnly,
    [JsonPropertyName("autoosd")]
    AutoOsd,
    [JsonPropertyName("autoonly")]
    AutoOnly,
    [JsonPropertyName("auto")]
    Auto,
    [JsonPropertyName("singlecolumn")]
    SingleColumn,
    [JsonPropertyName("singleblockvertical")]
    SingleBlockVertical,
    [JsonPropertyName("singleblock")]
    SingleBlock,
    [JsonPropertyName("singleline")]
    SingleLine,
    [JsonPropertyName("singleword")]
    SingleWord,
    [JsonPropertyName("circleword")]
    CircleWord,
    [JsonPropertyName("singlechar")]
    SingleChar,
}


/// <summary>
/// Custom JSON converter for <see cref="PSMMode"/> that respects explicit variant names.
/// </summary>
internal sealed class PSMModeJsonConverter : JsonConverter<PSMMode>
{
    public override PSMMode Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var value = reader.GetString();
        return value switch
        {
            "osdonly" => PSMMode.OsdOnly,
            "autoosd" => PSMMode.AutoOsd,
            "autoonly" => PSMMode.AutoOnly,
            "auto" => PSMMode.Auto,
            "singlecolumn" => PSMMode.SingleColumn,
            "singleblockvertical" => PSMMode.SingleBlockVertical,
            "singleblock" => PSMMode.SingleBlock,
            "singleline" => PSMMode.SingleLine,
            "singleword" => PSMMode.SingleWord,
            "circleword" => PSMMode.CircleWord,
            "singlechar" => PSMMode.SingleChar,
            _ => throw new JsonException($"Unknown PSMMode value: {value}")
        };
    }

    public override void Write(Utf8JsonWriter writer, PSMMode value, JsonSerializerOptions options)
    {
        var str = value switch
        {
            PSMMode.OsdOnly => "osdonly",
            PSMMode.AutoOsd => "autoosd",
            PSMMode.AutoOnly => "autoonly",
            PSMMode.Auto => "auto",
            PSMMode.SingleColumn => "singlecolumn",
            PSMMode.SingleBlockVertical => "singleblockvertical",
            PSMMode.SingleBlock => "singleblock",
            PSMMode.SingleLine => "singleline",
            PSMMode.SingleWord => "singleword",
            PSMMode.CircleWord => "circleword",
            PSMMode.SingleChar => "singlechar",
            _ => throw new JsonException($"Unknown PSMMode value: {value}")
        };
        writer.WriteStringValue(str);
    }
}
