// 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>
/// Structured data type classification.
/// </summary>
[JsonConverter(typeof(StructuredDataTypeJsonConverter))]
public enum StructuredDataType
{
    /// <summary>
    /// JSON-LD structured data
    /// </summary>
    [JsonPropertyName("json-ld")]
    JsonLd,
    /// <summary>
    /// Microdata
    /// </summary>
    [JsonPropertyName("microdata")]
    Microdata,
    /// <summary>
    /// RDFa
    /// </summary>
    [JsonPropertyName("rdfa")]
    RdFa,
}


/// <summary>
/// Custom JSON converter for <see cref="StructuredDataType"/> that respects explicit variant names.
/// </summary>
internal sealed class StructuredDataTypeJsonConverter : JsonConverter<StructuredDataType>
{
    public override StructuredDataType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var value = reader.GetString();
        return value switch
        {
            "json-ld" => StructuredDataType.JsonLd,
            "microdata" => StructuredDataType.Microdata,
            "rdfa" => StructuredDataType.RdFa,
            _ => throw new JsonException($"Unknown StructuredDataType value: {value}")
        };
    }

    public override void Write(Utf8JsonWriter writer, StructuredDataType value, JsonSerializerOptions options)
    {
        var str = value switch
        {
            StructuredDataType.JsonLd => "json-ld",
            StructuredDataType.Microdata => "microdata",
            StructuredDataType.RdFa => "rdfa",
            _ => throw new JsonException($"Unknown StructuredDataType value: {value}")
        };
        writer.WriteStringValue(str);
    }
}
