{{ header }}#nullable enable

using System;

namespace {{ namespace }};

/// <summary>Controls how the visitor affects the conversion pipeline.</summary>
public abstract record VisitResult
{
    private VisitResult() {}

    /// <summary>Proceed with default conversion.</summary>
    public sealed record Continue : VisitResult;

    /// <summary>Omit this element from output entirely.</summary>
    public sealed record Skip : VisitResult;

    /// <summary>Keep original HTML verbatim.</summary>
    public sealed record PreserveHtml : VisitResult;

    /// <summary>Replace with custom Markdown.</summary>
    public sealed record Custom(string Markdown) : VisitResult;

    /// <summary>Abort conversion with an error message.</summary>
    public sealed record Error(string Message) : VisitResult;

    internal string ToFfiJson() => this switch {
        VisitResult.Continue => "\"Continue\"",
        VisitResult.Skip => "\"Skip\"",
        VisitResult.PreserveHtml => "\"PreserveHtml\"",
        VisitResult.Custom c => "{{ \"{{\" }}\\\"Custom\\\":\" + System.Text.Json.JsonSerializer.Serialize(c.Markdown) + "{{ \"}}\" }}",
        VisitResult.Error e => "{{ \"{{\" }}\\\"Error\\\":\" + System.Text.Json.JsonSerializer.Serialize(e.Message) + "{{ \"}}\" }}",
        _ => "\"Continue\""
    };
}
