using Tiku.Application.Security;
using Tiku.Infrastructure.Persistence;

namespace Tiku.Infrastructure.Observability;

internal sealed class DependencyReadinessProbe(
    TikuDbContext dbContext,
    IRedisSecurityStore redisSecurityStore) : IDependencyReadinessProbe
{
    public async Task<DependencyReadiness> CheckAsync(CancellationToken cancellationToken = default)
    {
        var database = await dbContext.Database.CanConnectAsync(cancellationToken);
        var redis = !redisSecurityStore.IsConfigured || await redisSecurityStore.PingAsync(cancellationToken);
        return new DependencyReadiness(database && redis, DateTimeOffset.UtcNow);
    }
}