// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java
// public final class CreateApplicationInstance {
// 
// 	private final ServiceInstance serviceInstance;
// 
// 	public CreateApplicationInstance(ServiceInstance serviceInstance) {
// 		Assert.notNull(serviceInstance, "serviceInstance must not be null!");
// 		this.serviceInstance = serviceInstance;
// 	}
// 
// 	public ServiceInstance getServiceInstance() {
// 		return this.serviceInstance;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java
// public final class DeleteApplicationInstance {
// 
// 	private final String id;
// 
// 	public DeleteApplicationInstance(String id) {
// 		Assert.notNull(id, "id must not be null!");
// 		this.id = id;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java
// public final class UpdateActuatorEndpoints {
// 
// 	private final String id;
// 	private final Links actuatorEndpoints;
// 
// 	public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) {
// 		Assert.notNull(id, "id must not be null!");
// 		Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!");
// 		this.id = id;
// 		this.actuatorEndpoints = actuatorEndpoints;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// 
// 	public Links getActuatorEndpoints() {
// 		return this.actuatorEndpoints;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java
// public final class UpdateApplicationInstanceHealth {
// 
// 	private final String id;
// 	private final Status healthStatus;
// 
// 	public UpdateApplicationInstanceHealth(String id, Status healthStatus) {
// 		Assert.notNull(id, "id must not be null!");
// 		Assert.notNull(healthStatus, "healthStatus must not be null!");
// 
// 		this.id = id;
// 		this.healthStatus = healthStatus;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// 
// 	public Status getHealthStatus() {
// 		return this.healthStatus;
// 	}
// }


import java.util.List;
import java.util.Optional;
import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance;
import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance;
import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints;
import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth;
import org.springframework.cloud.client.ServiceInstance;

	public List<ApplicationInstance> getApplicationInstances() {
		return this.repository.getAll();
	}

	public String createApplicationInstance(CreateApplicationInstance command) {
		final ServiceInstance serviceInstance = command.getServiceInstance();
		ApplicationInstance applicationInstance = ApplicationInstance.Builder
				.forApplicationWithId(serviceInstance.getServiceId(), serviceInstance.getInstanceId())
				.baseUri(serviceInstance.getUri())
				.build();
		return this.repository.save(applicationInstance).getId();
	}

	public void updateApplicationInstanceHealth(final UpdateApplicationInstanceHealth command) {
		this.getById(command.getId())
				.ifPresent(applicationInstance -> {
					applicationInstance.updateHealthStatus(command.getHealthStatus());
					this.repository.save(applicationInstance);
				});
	}

	public void updateActuatorEndpoints(final UpdateActuatorEndpoints command) {
		this.getById(command.getId())
				.ifPresent(applicationInstance -> {
					applicationInstance.updateActuatorEndpoints(command.getActuatorEndpoints());
					this.repository.save(applicationInstance);
				});
	}

// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java
// public final class CreateApplicationInstance {
// 
// 	private final ServiceInstance serviceInstance;
// 
// 	public CreateApplicationInstance(ServiceInstance serviceInstance) {
// 		Assert.notNull(serviceInstance, "serviceInstance must not be null!");
// 		this.serviceInstance = serviceInstance;
// 	}
// 
// 	public ServiceInstance getServiceInstance() {
// 		return this.serviceInstance;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java
// public final class DeleteApplicationInstance {
// 
// 	private final String id;
// 
// 	public DeleteApplicationInstance(String id) {
// 		Assert.notNull(id, "id must not be null!");
// 		this.id = id;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java
// public final class UpdateActuatorEndpoints {
// 
// 	private final String id;
// 	private final Links actuatorEndpoints;
// 
// 	public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) {
// 		Assert.notNull(id, "id must not be null!");
// 		Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!");
// 		this.id = id;
// 		this.actuatorEndpoints = actuatorEndpoints;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// 
// 	public Links getActuatorEndpoints() {
// 		return this.actuatorEndpoints;
// 	}
// }
// 
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java
// public final class UpdateApplicationInstanceHealth {
// 
// 	private final String id;
// 	private final Status healthStatus;
// 
// 	public UpdateApplicationInstanceHealth(String id, Status healthStatus) {
// 		Assert.notNull(id, "id must not be null!");
// 		Assert.notNull(healthStatus, "healthStatus must not be null!");
// 
// 		this.id = id;
// 		this.healthStatus = healthStatus;
// 	}
// 
// 	public String getId() {
// 		return this.id;
// 	}
// 
// 	public Status getHealthStatus() {
// 		return this.healthStatus;
// 	}
// }


// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceService.java
import java.util.List;
import java.util.Optional;
import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance;
import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance;
import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints;
import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth;
import org.springframework.cloud.client.ServiceInstance;


	public List<ApplicationInstance> getApplicationInstances() {
		return this.repository.getAll();
	}

	public String createApplicationInstance(CreateApplicationInstance command) {
		final ServiceInstance serviceInstance = command.getServiceInstance();
		ApplicationInstance applicationInstance = ApplicationInstance.Builder
				.forApplicationWithId(serviceInstance.getServiceId(), serviceInstance.getInstanceId())
				.baseUri(serviceInstance.getUri())
				.build();
		return this.repository.save(applicationInstance).getId();
	}

	public void updateApplicationInstanceHealth(final UpdateApplicationInstanceHealth command) {
		this.getById(command.getId())
				.ifPresent(applicationInstance -> {
					applicationInstance.updateHealthStatus(command.getHealthStatus());
					this.repository.save(applicationInstance);
				});
	}

	public void updateActuatorEndpoints(final UpdateActuatorEndpoints command) {
		this.getById(command.getId())
				.ifPresent(applicationInstance -> {
					applicationInstance.updateActuatorEndpoints(command.getActuatorEndpoints());
					this.repository.save(applicationInstance);
				});
	}

	public void deleteApplicationInstance(final DeleteApplicationInstance command) {