using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options;
using Minio;
using Minio.DataModel.Args;

public class MinioHealthCheck : IHealthCheck
{
    private readonly IMinioClient _minio;
    private readonly string _bucketName;

    public MinioHealthCheck(IMinioClient minio, IOptions<MinioOptions> options)
    {
        _minio = minio;
        _bucketName = options.Value.BucketName;
    }

    public async Task<HealthCheckResult> CheckHealthAsync(
        HealthCheckContext context, CancellationToken cancellationToken = default)
    {
        var exists = await _minio.BucketExistsAsync(
            new BucketExistsArgs().WithBucket(_bucketName), cancellationToken);

        return exists
            ? HealthCheckResult.Healthy($"Bucket '{_bucketName}' exists.")
            : HealthCheckResult.Unhealthy($"Bucket '{_bucketName}' not found.");
    }
}
