// 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 an extracted URI.
/// </summary>
[JsonConverter(typeof(UriKindJsonConverter))]
public enum UriKind
{
    /// <summary>
    /// A clickable hyperlink (web URL, file link).
    /// </summary>
    [JsonPropertyName("hyperlink")]
    Hyperlink,
    /// <summary>
    /// An image or media resource reference.
    /// </summary>
    [JsonPropertyName("image")]
    Image,
    /// <summary>
    /// An internal anchor or cross-reference target.
    /// </summary>
    [JsonPropertyName("anchor")]
    Anchor,
    /// <summary>
    /// A citation or bibliographic reference (DOI, academic ref).
    /// </summary>
    [JsonPropertyName("citation")]
    Citation,
    /// <summary>
    /// A general reference (e.g. `\ref{}` in LaTeX, `:ref:` in RST).
    /// </summary>
    [JsonPropertyName("reference")]
    Reference,
    /// <summary>
    /// An email address (`mailto:` link or bare email).
    /// </summary>
    [JsonPropertyName("email")]
    Email,
}


/// <summary>
/// Custom JSON converter for <see cref="UriKind"/> that respects explicit variant names.
/// </summary>
internal sealed class UriKindJsonConverter : JsonConverter<UriKind>
{
    public override UriKind Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var value = reader.GetString();
        return value switch
        {
            "hyperlink" => UriKind.Hyperlink,
            "image" => UriKind.Image,
            "anchor" => UriKind.Anchor,
            "citation" => UriKind.Citation,
            "reference" => UriKind.Reference,
            "email" => UriKind.Email,
            _ => throw new JsonException($"Unknown UriKind value: {value}")
        };
    }

    public override void Write(Utf8JsonWriter writer, UriKind value, JsonSerializerOptions options)
    {
        var str = value switch
        {
            UriKind.Hyperlink => "hyperlink",
            UriKind.Image => "image",
            UriKind.Anchor => "anchor",
            UriKind.Citation => "citation",
            UriKind.Reference => "reference",
            UriKind.Email => "email",
            _ => throw new JsonException($"Unknown UriKind value: {value}")
        };
        writer.WriteStringValue(str);
    }
}
