// 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;
/*
 * Copyright 2015-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package be.ordina.msdashboard.applicationinstance;




/**
 * Application service to interact with an {@link ApplicationInstance application instance}.
 *
 * @author Tim Ysewyn
 * @author Steve De Zitter
 */
public class ApplicationInstanceService {

	private final ApplicationInstanceRepository repository;

	public ApplicationInstanceService(ApplicationInstanceRepository repository) {
		this.repository = repository;
	}

	public Optional<String> getApplicationInstanceIdForServiceInstance(ServiceInstance serviceInstance) {
		return this.getById(serviceInstance.getInstanceId())
				.map(ApplicationInstance::getId);
	}

	public Optional<ApplicationInstance> getById(String id) {
		return Optional.ofNullable(this.repository.getById(id));
	}

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

// 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;

/*
 * Copyright 2015-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package be.ordina.msdashboard.applicationinstance;




/**
 * Application service to interact with an {@link ApplicationInstance application instance}.
 *
 * @author Tim Ysewyn
 * @author Steve De Zitter
 */
public class ApplicationInstanceService {

	private final ApplicationInstanceRepository repository;

	public ApplicationInstanceService(ApplicationInstanceRepository repository) {
		this.repository = repository;
	}

	public Optional<String> getApplicationInstanceIdForServiceInstance(ServiceInstance serviceInstance) {
		return this.getById(serviceInstance.getInstanceId())
				.map(ApplicationInstance::getId);
	}

	public Optional<ApplicationInstance> getById(String id) {
		return Optional.ofNullable(this.repository.getById(id));
	}

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

	public String createApplicationInstance(CreateApplicationInstance command) {