// 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>
/// Link type classification.
/// </summary>
[JsonConverter(typeof(LinkTypeJsonConverter))]
public enum LinkType
{
    /// <summary>
    /// Anchor link (#section)
    /// </summary>
    [JsonPropertyName("anchor")]
    Anchor,
    /// <summary>
    /// Internal link (same domain)
    /// </summary>
    [JsonPropertyName("internal")]
    Internal,
    /// <summary>
    /// External link (different domain)
    /// </summary>
    [JsonPropertyName("external")]
    External,
    /// <summary>
    /// Email link (mailto:)
    /// </summary>
    [JsonPropertyName("email")]
    Email,
    /// <summary>
    /// Phone link (tel:)
    /// </summary>
    [JsonPropertyName("phone")]
    Phone,
    /// <summary>
    /// Other link type
    /// </summary>
    [JsonPropertyName("other")]
    Other,
}


/// <summary>
/// Custom JSON converter for <see cref="LinkType"/> that respects explicit variant names.
/// </summary>
internal sealed class LinkTypeJsonConverter : JsonConverter<LinkType>
{
    public override LinkType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var value = reader.GetString();
        return value switch
        {
            "anchor" => LinkType.Anchor,
            "internal" => LinkType.Internal,
            "external" => LinkType.External,
            "email" => LinkType.Email,
            "phone" => LinkType.Phone,
            "other" => LinkType.Other,
            _ => throw new JsonException($"Unknown LinkType value: {value}")
        };
    }

    public override void Write(Utf8JsonWriter writer, LinkType value, JsonSerializerOptions options)
    {
        var str = value switch
        {
            LinkType.Anchor => "anchor",
            LinkType.Internal => "internal",
            LinkType.External => "external",
            LinkType.Email => "email",
            LinkType.Phone => "phone",
            LinkType.Other => "other",
            _ => throw new JsonException($"Unknown LinkType value: {value}")
        };
        writer.WriteStringValue(str);
    }
}
