// Path: snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/SnoopEEConfigurationException.java
// public class SnoopEEConfigurationException extends RuntimeException {
// 
//     public SnoopEEConfigurationException(String message) {
//         super(message);
//     }
// }
// 
// Path: snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/client/SnoopEEConfig.java
// public class SnoopEEConfig {
// 
//     private String serviceName;
//     private String serviceHome;
//     private String serviceRoot;
// 
//     public String getServiceName() {
//         return serviceName;
//     }
// 
//     public void setServiceName(String serviceName) {
//         this.serviceName = serviceName;
//     }
// 
//     public String getServiceHome() {
//         return serviceHome;
//     }
// 
//     public void setServiceHome(String serviceHome) {
//         this.serviceHome = serviceHome;
//     }
// 
//     public String getServiceRoot() {
//         return serviceRoot;
//     }
// 
//     public void setServiceRoot(String serviceRoot) {
//         this.serviceRoot = serviceRoot;
//     }
// 
//     public String toJSON() {
// 
//         Writer w = new StringWriter();
//         try (JsonGenerator generator = Json.createGenerator(w)) {
// 
//             generator.writeStartObject()
//                     .write("serviceName", serviceName)
//                     .write("serviceHome", serviceHome)
//                     .write("serviceRoot", serviceRoot)
//                     .writeEnd();
//         }
// 
//         return w.toString();
//     }
// 
//     public static SnoopEEConfig fromJSON(String json) {
// 
//         SnoopEEConfig config = new SnoopEEConfig();
// 
//         try (JsonReader reader = Json.createReader(new StringReader(json))) {
// 
//             JsonObject configJson = reader.readObject();
// 
//             config.setServiceName(configJson.getString("serviceName"));
//             config.setServiceHome(configJson.getString("serviceHome"));
//             config.setServiceRoot(configJson.getString("serviceRoot"));
//         }
// 
//         return config;
//     }
// }


import eu.agilejava.snoopee.SnoopEEConfigurationException;
import eu.agilejava.snoopee.annotation.SnoopEEClient;
import eu.agilejava.snoopee.client.SnoopEEConfig;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import javax.annotation.PreDestroy;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Initialized;
import javax.enterprise.event.Event;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Logger;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
    private String serviceRoot;

    private final SnoopEEConfig applicationConfig = new SnoopEEConfig();

    private Timer timer;

    @Inject
    private Event<SnoopEEConfig> configuredEvent;

    private void init(@Observes @Initialized(ApplicationScoped.class) Object init) {
        LOGGER.config("Checking if SnoopEE is enabled");

        if (SnoopEEExtensionHelper.isSnoopEnabled()) {

            Client client = ClientBuilder.newClient();

            try {
                readConfiguration();
                LOGGER.config(() -> "Registering " + applicationConfig.getServiceName());

                Response response = client
                        .target(serviceUrl)
                        .path("api")
                        .path("services")
                        .request()
                        .post(Entity.entity(applicationConfig, APPLICATION_JSON));

                LOGGER.config(() -> "Fire health event");
                configuredEvent.fire(applicationConfig);

// Path: snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/SnoopEEConfigurationException.java
// public class SnoopEEConfigurationException extends RuntimeException {
// 
//     public SnoopEEConfigurationException(String message) {
//         super(message);
//     }
// }
// 
// Path: snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/client/SnoopEEConfig.java
// public class SnoopEEConfig {
// 
//     private String serviceName;
//     private String serviceHome;
//     private String serviceRoot;
// 
//     public String getServiceName() {
//         return serviceName;
//     }
// 
//     public void setServiceName(String serviceName) {
//         this.serviceName = serviceName;
//     }
// 
//     public String getServiceHome() {
//         return serviceHome;
//     }
// 
//     public void setServiceHome(String serviceHome) {
//         this.serviceHome = serviceHome;
//     }
// 
//     public String getServiceRoot() {
//         return serviceRoot;
//     }
// 
//     public void setServiceRoot(String serviceRoot) {
//         this.serviceRoot = serviceRoot;
//     }
// 
//     public String toJSON() {
// 
//         Writer w = new StringWriter();
//         try (JsonGenerator generator = Json.createGenerator(w)) {
// 
//             generator.writeStartObject()
//                     .write("serviceName", serviceName)
//                     .write("serviceHome", serviceHome)
//                     .write("serviceRoot", serviceRoot)
//                     .writeEnd();
//         }
// 
//         return w.toString();
//     }
// 
//     public static SnoopEEConfig fromJSON(String json) {
// 
//         SnoopEEConfig config = new SnoopEEConfig();
// 
//         try (JsonReader reader = Json.createReader(new StringReader(json))) {
// 
//             JsonObject configJson = reader.readObject();
// 
//             config.setServiceName(configJson.getString("serviceName"));
//             config.setServiceHome(configJson.getString("serviceHome"));
//             config.setServiceRoot(configJson.getString("serviceRoot"));
//         }
// 
//         return config;
//     }
// }


// Path: snoopee-discovery/snoopee-micro/src/main/java/eu/agilejava/snoopee/scan/SnoopEERegistrationClient.java
import eu.agilejava.snoopee.SnoopEEConfigurationException;
import eu.agilejava.snoopee.annotation.SnoopEEClient;
import eu.agilejava.snoopee.client.SnoopEEConfig;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import javax.annotation.PreDestroy;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Initialized;
import javax.enterprise.event.Event;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Logger;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;

    private String serviceRoot;

    private final SnoopEEConfig applicationConfig = new SnoopEEConfig();

    private Timer timer;

    @Inject
    private Event<SnoopEEConfig> configuredEvent;

    private void init(@Observes @Initialized(ApplicationScoped.class) Object init) {
        LOGGER.config("Checking if SnoopEE is enabled");

        if (SnoopEEExtensionHelper.isSnoopEnabled()) {

            Client client = ClientBuilder.newClient();

            try {
                readConfiguration();
                LOGGER.config(() -> "Registering " + applicationConfig.getServiceName());

                Response response = client
                        .target(serviceUrl)
                        .path("api")
                        .path("services")
                        .request()
                        .post(Entity.entity(applicationConfig, APPLICATION_JSON));

                LOGGER.config(() -> "Fire health event");
                configuredEvent.fire(applicationConfig);

            } catch (SnoopEEConfigurationException e) {