// 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>
/// ONNX Runtime execution provider type.
///
/// Determines which hardware backend is used for model inference.
/// `Auto` (default) selects the best available provider per platform.
/// </summary>
[JsonConverter(typeof(ExecutionProviderTypeJsonConverter))]
public enum ExecutionProviderType
{
    /// <summary>
    /// Auto-select: CoreML on macOS, CUDA on Linux, CPU elsewhere.
    /// </summary>
    [JsonPropertyName("auto")]
    Auto,
    /// <summary>
    /// CPU execution provider (always available).
    /// </summary>
    [JsonPropertyName("cpu")]
    Cpu,
    /// <summary>
    /// Apple CoreML (macOS/iOS Neural Engine + GPU).
    /// </summary>
    [JsonPropertyName("coreml")]
    CoreMl,
    /// <summary>
    /// NVIDIA CUDA GPU acceleration.
    /// </summary>
    [JsonPropertyName("cuda")]
    Cuda,
    /// <summary>
    /// NVIDIA TensorRT (optimized CUDA inference).
    /// </summary>
    [JsonPropertyName("tensorrt")]
    TensorRt,
}


/// <summary>
/// Custom JSON converter for <see cref="ExecutionProviderType"/> that respects explicit variant names.
/// </summary>
internal sealed class ExecutionProviderTypeJsonConverter : JsonConverter<ExecutionProviderType>
{
    public override ExecutionProviderType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var value = reader.GetString();
        return value switch
        {
            "auto" => ExecutionProviderType.Auto,
            "cpu" => ExecutionProviderType.Cpu,
            "coreml" => ExecutionProviderType.CoreMl,
            "cuda" => ExecutionProviderType.Cuda,
            "tensorrt" => ExecutionProviderType.TensorRt,
            _ => throw new JsonException($"Unknown ExecutionProviderType value: {value}")
        };
    }

    public override void Write(Utf8JsonWriter writer, ExecutionProviderType value, JsonSerializerOptions options)
    {
        var str = value switch
        {
            ExecutionProviderType.Auto => "auto",
            ExecutionProviderType.Cpu => "cpu",
            ExecutionProviderType.CoreMl => "coreml",
            ExecutionProviderType.Cuda => "cuda",
            ExecutionProviderType.TensorRt => "tensorrt",
            _ => throw new JsonException($"Unknown ExecutionProviderType value: {value}")
        };
        writer.WriteStringValue(str);
    }
}
