using Microsoft.EntityFrameworkCore;
using OmsorgCore.Application.Abstractions;

namespace OmsorgCore.Infrastructure.Persistence;

public sealed class DatabaseConnectivityChecker : IDatabaseConnectivityChecker
{
    private readonly OmsorgCoreDbContext _db;

    public DatabaseConnectivityChecker(OmsorgCoreDbContext db)
    {
        _db = db;
    }

    public async Task<bool> CanConnectAsync(CancellationToken cancellationToken)
    {
        try
        {
            return await _db.Database.CanConnectAsync(cancellationToken);
        }
        catch
        {
            return false;
        }
    }
}
