#nullable enable
using Baya.Application.Contracts.Common;

namespace Baya.Application.Features.Reviews;

/// <summary>Cache-key scheme for the public per-nurse rating aggregate. The aggregate read is cached; every
/// moderation transition that can change it invalidates the nurse's key so a stale, inflated average is never
/// served.</summary>
internal static class ReviewCache
{
    private static readonly TimeSpan AggregateTtl = TimeSpan.FromMinutes(10);

    public static string AggregateKey(long nurseProfileId) => $"nurse_review_agg:{nurseProfileId}";

    public static TimeSpan Ttl => AggregateTtl;

    public static ValueTask InvalidateAggregateAsync(ICacheService cache, long nurseProfileId, CancellationToken cancellationToken)
        => cache.RemoveAsync(AggregateKey(nurseProfileId), cancellationToken);
}
