// 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>
/// Processing stages for post-processors.
///
/// Post-processors are executed in stage order (Early → Middle → Late).
/// Use stages to control the order of post-processing operations.
/// </summary>
[JsonConverter(typeof(ProcessingStageJsonConverter))]
public enum ProcessingStage
{
    /// <summary>
    /// Early stage - foundational processing.
    ///
    /// Use for:
    /// - Language detection
    /// - Character encoding normalization
    /// - Entity extraction (NER)
    /// - Text quality scoring
    /// </summary>
    [JsonPropertyName("early")]
    Early,
    /// <summary>
    /// Middle stage - content transformation.
    ///
    /// Use for:
    /// - Keyword extraction
    /// - Token reduction
    /// - Text summarization
    /// - Semantic analysis
    /// </summary>
    [JsonPropertyName("middle")]
    Middle,
    /// <summary>
    /// Late stage - final enrichment.
    ///
    /// Use for:
    /// - Custom user hooks
    /// - Analytics/logging
    /// - Final validation
    /// - Output formatting
    /// </summary>
    [JsonPropertyName("late")]
    Late,
}


/// <summary>
/// Custom JSON converter for <see cref="ProcessingStage"/> that respects explicit variant names.
/// </summary>
internal sealed class ProcessingStageJsonConverter : JsonConverter<ProcessingStage>
{
    public override ProcessingStage Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var value = reader.GetString();
        return value switch
        {
            "early" => ProcessingStage.Early,
            "middle" => ProcessingStage.Middle,
            "late" => ProcessingStage.Late,
            _ => throw new JsonException($"Unknown ProcessingStage value: {value}")
        };
    }

    public override void Write(Utf8JsonWriter writer, ProcessingStage value, JsonSerializerOptions options)
    {
        var str = value switch
        {
            ProcessingStage.Early => "early",
            ProcessingStage.Middle => "middle",
            ProcessingStage.Late => "late",
            _ => throw new JsonException($"Unknown ProcessingStage value: {value}")
        };
        writer.WriteStringValue(str);
    }
}
