// 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>
/// Types of block-level elements in Djot.
/// </summary>
[JsonConverter(typeof(BlockTypeJsonConverter))]
public enum BlockType
{
    [JsonPropertyName("paragraph")]
    Paragraph,
    [JsonPropertyName("heading")]
    Heading,
    [JsonPropertyName("blockquote")]
    Blockquote,
    [JsonPropertyName("code_block")]
    CodeBlock,
    [JsonPropertyName("list_item")]
    ListItem,
    [JsonPropertyName("ordered_list")]
    OrderedList,
    [JsonPropertyName("bullet_list")]
    BulletList,
    [JsonPropertyName("task_list")]
    TaskList,
    [JsonPropertyName("definition_list")]
    DefinitionList,
    [JsonPropertyName("definition_term")]
    DefinitionTerm,
    [JsonPropertyName("definition_description")]
    DefinitionDescription,
    [JsonPropertyName("div")]
    Div,
    [JsonPropertyName("section")]
    Section,
    [JsonPropertyName("thematic_break")]
    ThematicBreak,
    [JsonPropertyName("raw_block")]
    RawBlock,
    [JsonPropertyName("math_display")]
    MathDisplay,
}


/// <summary>
/// Custom JSON converter for <see cref="BlockType"/> that respects explicit variant names.
/// </summary>
internal sealed class BlockTypeJsonConverter : JsonConverter<BlockType>
{
    public override BlockType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var value = reader.GetString();
        return value switch
        {
            "paragraph" => BlockType.Paragraph,
            "heading" => BlockType.Heading,
            "blockquote" => BlockType.Blockquote,
            "code_block" => BlockType.CodeBlock,
            "list_item" => BlockType.ListItem,
            "ordered_list" => BlockType.OrderedList,
            "bullet_list" => BlockType.BulletList,
            "task_list" => BlockType.TaskList,
            "definition_list" => BlockType.DefinitionList,
            "definition_term" => BlockType.DefinitionTerm,
            "definition_description" => BlockType.DefinitionDescription,
            "div" => BlockType.Div,
            "section" => BlockType.Section,
            "thematic_break" => BlockType.ThematicBreak,
            "raw_block" => BlockType.RawBlock,
            "math_display" => BlockType.MathDisplay,
            _ => throw new JsonException($"Unknown BlockType value: {value}")
        };
    }

    public override void Write(Utf8JsonWriter writer, BlockType value, JsonSerializerOptions options)
    {
        var str = value switch
        {
            BlockType.Paragraph => "paragraph",
            BlockType.Heading => "heading",
            BlockType.Blockquote => "blockquote",
            BlockType.CodeBlock => "code_block",
            BlockType.ListItem => "list_item",
            BlockType.OrderedList => "ordered_list",
            BlockType.BulletList => "bullet_list",
            BlockType.TaskList => "task_list",
            BlockType.DefinitionList => "definition_list",
            BlockType.DefinitionTerm => "definition_term",
            BlockType.DefinitionDescription => "definition_description",
            BlockType.Div => "div",
            BlockType.Section => "section",
            BlockType.ThematicBreak => "thematic_break",
            BlockType.RawBlock => "raw_block",
            BlockType.MathDisplay => "math_display",
            _ => throw new JsonException($"Unknown BlockType value: {value}")
        };
        writer.WriteStringValue(str);
    }
}
