package org.gameontext.player;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.eclipse.microprofile.health.Health;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;


@Health
@ApplicationScoped
public class PlayerHealth implements HealthCheck {

    @Inject
    protected CouchDbHealth dbHealth;

    @Override
    public HealthCheckResponse call() {
      if ( dbHealth.isHealthy() ) {
          return HealthCheckResponse.named(PlayersResource.class.getSimpleName())
                                    .withData(dbHealth.getDatabaseName(), "available").up().build();
      }
      return HealthCheckResponse.named(PlayersResource.class.getSimpleName())
                                .withData(dbHealth.getDatabaseName(), "down").down()
                                .build();
    }
    
    public boolean isHealthy() {
        try {
            return db.getConnection() != null && db.getDbInfo() != null;
        }
        catch(Exception e) {
            return false;
        }
    }
}

@@ -892,212 +892,6 @@
   %7D%0A
-    %0A    public boolean isHealthy() %7B%0A        try %7B%0A            return db.getConnection() != null && db.getDbInfo() != null;%0A        %7D%0A        catch(Exception e) %7B%0A            return false;%0A        %7D%0A    %7D%0A
 %7D%0A

fix bad merge