// 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 kind of a relationship between document elements.
/// </summary>
[JsonConverter(typeof(RelationshipKindJsonConverter))]
public enum RelationshipKind
{
    /// <summary>
    /// Footnote marker -&gt; footnote definition.
    /// </summary>
    [JsonPropertyName("footnote_reference")]
    FootnoteReference,
    /// <summary>
    /// Citation marker -&gt; bibliography entry.
    /// </summary>
    [JsonPropertyName("citation_reference")]
    CitationReference,
    /// <summary>
    /// Internal anchor link (`#id`) -&gt; target heading/element.
    /// </summary>
    [JsonPropertyName("internal_link")]
    InternalLink,
    /// <summary>
    /// Caption paragraph -&gt; figure/table it describes.
    /// </summary>
    [JsonPropertyName("caption")]
    Caption,
    /// <summary>
    /// Label -&gt; labeled element (HTML `&lt;label for&gt;`, LaTeX `\label{}`).
    /// </summary>
    [JsonPropertyName("label")]
    Label,
    /// <summary>
    /// TOC entry -&gt; target section.
    /// </summary>
    [JsonPropertyName("toc_entry")]
    TocEntry,
    /// <summary>
    /// Cross-reference (LaTeX `\ref{}`, DOCX cross-reference field).
    /// </summary>
    [JsonPropertyName("cross_reference")]
    CrossReference,
}


/// <summary>
/// Custom JSON converter for <see cref="RelationshipKind"/> that respects explicit variant names.
/// </summary>
internal sealed class RelationshipKindJsonConverter : JsonConverter<RelationshipKind>
{
    public override RelationshipKind Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var value = reader.GetString();
        return value switch
        {
            "footnote_reference" => RelationshipKind.FootnoteReference,
            "citation_reference" => RelationshipKind.CitationReference,
            "internal_link" => RelationshipKind.InternalLink,
            "caption" => RelationshipKind.Caption,
            "label" => RelationshipKind.Label,
            "toc_entry" => RelationshipKind.TocEntry,
            "cross_reference" => RelationshipKind.CrossReference,
            _ => throw new JsonException($"Unknown RelationshipKind value: {value}")
        };
    }

    public override void Write(Utf8JsonWriter writer, RelationshipKind value, JsonSerializerOptions options)
    {
        var str = value switch
        {
            RelationshipKind.FootnoteReference => "footnote_reference",
            RelationshipKind.CitationReference => "citation_reference",
            RelationshipKind.InternalLink => "internal_link",
            RelationshipKind.Caption => "caption",
            RelationshipKind.Label => "label",
            RelationshipKind.TocEntry => "toc_entry",
            RelationshipKind.CrossReference => "cross_reference",
            _ => throw new JsonException($"Unknown RelationshipKind value: {value}")
        };
        writer.WriteStringValue(str);
    }
}
