using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace StellaOps.Feedser.Storage.Mongo.Aliases;

public interface IAliasStore
{
    Task<AliasUpsertResult> ReplaceAsync(
        string advisoryKey,
        IEnumerable<AliasEntry> aliases,
        DateTimeOffset updatedAt,
        CancellationToken cancellationToken);

    Task<IReadOnlyList<AliasRecord>> GetByAliasAsync(string scheme, string value, CancellationToken cancellationToken);

    Task<IReadOnlyList<AliasRecord>> GetByAdvisoryAsync(string advisoryKey, CancellationToken cancellationToken);
}

public sealed record AliasEntry(string Scheme, string Value);

public sealed record AliasRecord(string AdvisoryKey, string Scheme, string Value, DateTimeOffset UpdatedAt);

public sealed record AliasCollision(string Scheme, string Value, IReadOnlyList<string> AdvisoryKeys);

public sealed record AliasUpsertResult(string AdvisoryKey, IReadOnlyList<AliasCollision> Collisions);
