using EventFlow.Aggregates;
using EventFlow.Core;

namespace Books.Api.EventFlow.Infrastructure;

/// <summary>
/// Service for repopulating read models for a single aggregate by replaying events from the event store.
/// Used by <see cref="ReadModelRepopulationJob"/> to repair read model inconsistencies.
/// </summary>
public interface ISingleAggregateReadModelPopulator
{
    /// <summary>
    /// Repopulates a specific read model for the given aggregate by replaying all its events.
    /// </summary>
    Task PopulateAsync<TAggregate, TIdentity>(TIdentity id, Type readModelType)
        where TAggregate : IAggregateRoot<TIdentity>
        where TIdentity : IIdentity;

    /// <summary>
    /// Repopulates ALL read models that handle events for the given aggregate.
    /// </summary>
    Task PopulateAllCompatibleReadModelsAsync<TAggregate, TIdentity>(TIdentity id)
        where TAggregate : IAggregateRoot<TIdentity>
        where TIdentity : IIdentity;

    /// <summary>
    /// Non-generic version for use with Hangfire background jobs.
    /// </summary>
    Task PopulateAsyncNonGeneric(Type aggregateType, Type identityType, string id, Type readModelType);
}
