// 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>
/// Semantic classification of a tracked change.
/// </summary>
[JsonConverter(typeof(RevisionKindJsonConverter))]
public enum RevisionKind
{
    /// <summary>
    /// Text or content was inserted.
    /// </summary>
    [JsonPropertyName("insertion")]
    Insertion,
    /// <summary>
    /// Text or content was deleted.
    /// </summary>
    [JsonPropertyName("deletion")]
    Deletion,
    /// <summary>
    /// Run-level formatting (font, size, colour, …) was changed.
    /// </summary>
    [JsonPropertyName("format_change")]
    FormatChange,
    /// <summary>
    /// A reviewer comment or annotation.
    /// </summary>
    [JsonPropertyName("comment")]
    Comment,
}


/// <summary>
/// Custom JSON converter for <see cref="RevisionKind"/> that respects explicit variant names.
/// </summary>
internal sealed class RevisionKindJsonConverter : JsonConverter<RevisionKind>
{
    public override RevisionKind Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var value = reader.GetString();
        return value switch
        {
            "insertion" => RevisionKind.Insertion,
            "deletion" => RevisionKind.Deletion,
            "format_change" => RevisionKind.FormatChange,
            "comment" => RevisionKind.Comment,
            _ => throw new JsonException($"Unknown RevisionKind value: {value}")
        };
    }

    public override void Write(Utf8JsonWriter writer, RevisionKind value, JsonSerializerOptions options)
    {
        var str = value switch
        {
            RevisionKind.Insertion => "insertion",
            RevisionKind.Deletion => "deletion",
            RevisionKind.FormatChange => "format_change",
            RevisionKind.Comment => "comment",
            _ => throw new JsonException($"Unknown RevisionKind value: {value}")
        };
        writer.WriteStringValue(str);
    }
}
