using Microsoft.AspNetCore.Mvc;
using OmsorgCore.Application.Abstractions;

namespace OmsorgCore.Api.Controllers;

[ApiController]
[Route("api/health")]
public class HealthController : ControllerBase
{
    private readonly IDatabaseConnectivityChecker _databaseConnectivityChecker;

    public HealthController(IDatabaseConnectivityChecker databaseConnectivityChecker)
    {
        _databaseConnectivityChecker = databaseConnectivityChecker;
    }

    [HttpGet]
    public async Task<IActionResult> Get(CancellationToken cancellationToken)
    {
        var databaseReachable = await _databaseConnectivityChecker.CanConnectAsync(cancellationToken);
        return Ok(new { status = "ok", databaseReachable });
    }
}
