// 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>
/// Type of text chunker to use.
///
/// # Variants
///
/// * `Text` - Generic text splitter, splits on whitespace and punctuation
/// * `Markdown` - Markdown-aware splitter, preserves formatting and structure
/// * `Yaml` - YAML-aware splitter, creates one chunk per top-level key
/// * `Semantic` - Topic-aware chunker. With an `EmbeddingConfig`, splits at
///   embedding-based topic shifts tuned by `topic_threshold` (default 0.75,
///   lower = more splits). Without an embedding, falls back to a
///   structural-boundary heuristic (ALL-CAPS headers, numbered sections,
///   blank-line paragraphs) and merges groups into chunks capped at
///   `max_characters` (default 1000). `topic_threshold` has no effect in the
///   fallback path. For best results, pair with an embedding model.
/// </summary>
[JsonConverter(typeof(ChunkerTypeJsonConverter))]
public enum ChunkerType
{
    [JsonPropertyName("text")]
    Text,
    [JsonPropertyName("markdown")]
    Markdown,
    [JsonPropertyName("yaml")]
    Yaml,
    [JsonPropertyName("semantic")]
    Semantic,
}


/// <summary>
/// Custom JSON converter for <see cref="ChunkerType"/> that respects explicit variant names.
/// </summary>
internal sealed class ChunkerTypeJsonConverter : JsonConverter<ChunkerType>
{
    public override ChunkerType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var value = reader.GetString();
        return value switch
        {
            "text" => ChunkerType.Text,
            "markdown" => ChunkerType.Markdown,
            "yaml" => ChunkerType.Yaml,
            "semantic" => ChunkerType.Semantic,
            _ => throw new JsonException($"Unknown ChunkerType value: {value}")
        };
    }

    public override void Write(Utf8JsonWriter writer, ChunkerType value, JsonSerializerOptions options)
    {
        var str = value switch
        {
            ChunkerType.Text => "text",
            ChunkerType.Markdown => "markdown",
            ChunkerType.Yaml => "yaml",
            ChunkerType.Semantic => "semantic",
            _ => throw new JsonException($"Unknown ChunkerType value: {value}")
        };
        writer.WriteStringValue(str);
    }
}
