// 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>
/// The 17 canonical document layout classes.
///
/// All model backends (RT-DETR, YOLO, etc.) map their native class IDs
/// to this shared set. Models with fewer classes (DocLayNet: 11, PubLayNet: 5)
/// map to the closest equivalent.
///
/// Wire format is snake_case in all serializers (JSON, TOML, YAML).
/// </summary>
[JsonConverter(typeof(LayoutClassJsonConverter))]
public enum LayoutClass
{
    [JsonPropertyName("caption")]
    Caption,
    [JsonPropertyName("footnote")]
    Footnote,
    [JsonPropertyName("formula")]
    Formula,
    [JsonPropertyName("list_item")]
    ListItem,
    [JsonPropertyName("page_footer")]
    PageFooter,
    [JsonPropertyName("page_header")]
    PageHeader,
    [JsonPropertyName("picture")]
    Picture,
    [JsonPropertyName("section_header")]
    SectionHeader,
    [JsonPropertyName("table")]
    Table,
    [JsonPropertyName("text")]
    Text,
    [JsonPropertyName("title")]
    Title,
    [JsonPropertyName("document_index")]
    DocumentIndex,
    [JsonPropertyName("code")]
    Code,
    [JsonPropertyName("checkbox_selected")]
    CheckboxSelected,
    [JsonPropertyName("checkbox_unselected")]
    CheckboxUnselected,
    [JsonPropertyName("form")]
    Form,
    [JsonPropertyName("key_value_region")]
    KeyValueRegion,
}


/// <summary>
/// Custom JSON converter for <see cref="LayoutClass"/> that respects explicit variant names.
/// </summary>
internal sealed class LayoutClassJsonConverter : JsonConverter<LayoutClass>
{
    public override LayoutClass Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var value = reader.GetString();
        return value switch
        {
            "caption" => LayoutClass.Caption,
            "footnote" => LayoutClass.Footnote,
            "formula" => LayoutClass.Formula,
            "list_item" => LayoutClass.ListItem,
            "page_footer" => LayoutClass.PageFooter,
            "page_header" => LayoutClass.PageHeader,
            "picture" => LayoutClass.Picture,
            "section_header" => LayoutClass.SectionHeader,
            "table" => LayoutClass.Table,
            "text" => LayoutClass.Text,
            "title" => LayoutClass.Title,
            "document_index" => LayoutClass.DocumentIndex,
            "code" => LayoutClass.Code,
            "checkbox_selected" => LayoutClass.CheckboxSelected,
            "checkbox_unselected" => LayoutClass.CheckboxUnselected,
            "form" => LayoutClass.Form,
            "key_value_region" => LayoutClass.KeyValueRegion,
            _ => throw new JsonException($"Unknown LayoutClass value: {value}")
        };
    }

    public override void Write(Utf8JsonWriter writer, LayoutClass value, JsonSerializerOptions options)
    {
        var str = value switch
        {
            LayoutClass.Caption => "caption",
            LayoutClass.Footnote => "footnote",
            LayoutClass.Formula => "formula",
            LayoutClass.ListItem => "list_item",
            LayoutClass.PageFooter => "page_footer",
            LayoutClass.PageHeader => "page_header",
            LayoutClass.Picture => "picture",
            LayoutClass.SectionHeader => "section_header",
            LayoutClass.Table => "table",
            LayoutClass.Text => "text",
            LayoutClass.Title => "title",
            LayoutClass.DocumentIndex => "document_index",
            LayoutClass.Code => "code",
            LayoutClass.CheckboxSelected => "checkbox_selected",
            LayoutClass.CheckboxUnselected => "checkbox_unselected",
            LayoutClass.Form => "form",
            LayoutClass.KeyValueRegion => "key_value_region",
            _ => throw new JsonException($"Unknown LayoutClass value: {value}")
        };
        writer.WriteStringValue(str);
    }
}
