using System;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace StellaOps.Vexer.Core;

/// <summary>
/// Normalizer contract for translating raw connector documents into canonical claims.
/// </summary>
public interface IVexNormalizer
{
    string Format { get; }

    bool CanHandle(VexRawDocument document);

    ValueTask<VexClaimBatch> NormalizeAsync(VexRawDocument document, VexProvider provider, CancellationToken cancellationToken);
}

/// <summary>
/// Registry that maps formats to registered normalizers.
/// </summary>
public sealed record VexNormalizerRegistry(ImmutableArray<IVexNormalizer> Normalizers)
{
    public IVexNormalizer? Resolve(VexRawDocument document)
        => Normalizers.FirstOrDefault(normalizer => normalizer.CanHandle(document));
}
