// 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>
/// Image type classification.
/// </summary>
[JsonConverter(typeof(ImageTypeJsonConverter))]
public enum ImageType
{
    /// <summary>
    /// Data URI image
    /// </summary>
    [JsonPropertyName("data-uri")]
    DataUri,
    /// <summary>
    /// Inline SVG
    /// </summary>
    [JsonPropertyName("inline-svg")]
    InlineSvg,
    /// <summary>
    /// External image URL
    /// </summary>
    [JsonPropertyName("external")]
    External,
    /// <summary>
    /// Relative path image
    /// </summary>
    [JsonPropertyName("relative")]
    Relative,
}


/// <summary>
/// Custom JSON converter for <see cref="ImageType"/> that respects explicit variant names.
/// </summary>
internal sealed class ImageTypeJsonConverter : JsonConverter<ImageType>
{
    public override ImageType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var value = reader.GetString();
        return value switch
        {
            "data-uri" => ImageType.DataUri,
            "inline-svg" => ImageType.InlineSvg,
            "external" => ImageType.External,
            "relative" => ImageType.Relative,
            _ => throw new JsonException($"Unknown ImageType value: {value}")
        };
    }

    public override void Write(Utf8JsonWriter writer, ImageType value, JsonSerializerOptions options)
    {
        var str = value switch
        {
            ImageType.DataUri => "data-uri",
            ImageType.InlineSvg => "inline-svg",
            ImageType.External => "external",
            ImageType.Relative => "relative",
            _ => throw new JsonException($"Unknown ImageType value: {value}")
        };
        writer.WriteStringValue(str);
    }
}
