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

namespace Tiku.Infrastructure.Observability;

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