// 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>
/// Type of paginated unit in a document.
///
/// Distinguishes between different types of "pages" (PDF pages, presentation slides, spreadsheet sheets).
/// </summary>
[JsonConverter(typeof(PageUnitTypeJsonConverter))]
public enum PageUnitType
{
    /// <summary>
    /// Standard document pages (PDF, DOCX, images)
    /// </summary>
    [JsonPropertyName("page")]
    Page,
    /// <summary>
    /// Presentation slides (PPTX, ODP)
    /// </summary>
    [JsonPropertyName("slide")]
    Slide,
    /// <summary>
    /// Spreadsheet sheets (XLSX, ODS)
    /// </summary>
    [JsonPropertyName("sheet")]
    Sheet,
}


/// <summary>
/// Custom JSON converter for <see cref="PageUnitType"/> that respects explicit variant names.
/// </summary>
internal sealed class PageUnitTypeJsonConverter : JsonConverter<PageUnitType>
{
    public override PageUnitType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var value = reader.GetString();
        return value switch
        {
            "page" => PageUnitType.Page,
            "slide" => PageUnitType.Slide,
            "sheet" => PageUnitType.Sheet,
            _ => throw new JsonException($"Unknown PageUnitType value: {value}")
        };
    }

    public override void Write(Utf8JsonWriter writer, PageUnitType value, JsonSerializerOptions options)
    {
        var str = value switch
        {
            PageUnitType.Page => "page",
            PageUnitType.Slide => "slide",
            PageUnitType.Sheet => "sheet",
            _ => throw new JsonException($"Unknown PageUnitType value: {value}")
        };
        writer.WriteStringValue(str);
    }
}
