// Port of Go conf/lex.go token types.

using System.Text.Json;

namespace NATS.Server.Configuration;

public enum TokenType
{
    Error,
    Eof,
    Key,
    Text,
    String,
    Bool,
    Integer,
    Float,
    DateTime,
    ArrayStart,
    ArrayEnd,
    MapStart,
    MapEnd,
    Variable,
    Include,
    Comment,
}

public readonly record struct Token(TokenType Type, string Value, int Line, int Position);

/// <summary>
/// Pedantic token wrapper matching Go conf/parse.go token accessors.
/// </summary>
public sealed class PedanticToken
{
    private readonly Token _item;
    private readonly object? _value;
    private readonly bool _usedVariable;
    private readonly string _sourceFile;

    public PedanticToken(Token item, object? value = null, bool usedVariable = false, string sourceFile = "")
    {
        _item = item;
        _value = value;
        _usedVariable = usedVariable;
        _sourceFile = sourceFile ?? string.Empty;
    }

    public string MarshalJson() => JsonSerializer.Serialize(Value());

    public object? Value() => _value ?? _item.Value;

    public int Line() => _item.Line;

    public bool IsUsedVariable() => _usedVariable;

    public string SourceFile() => _sourceFile;

    public int Position() => _item.Position;
}
