package it.reply.orchestrator.service.commands;

import it.reply.orchestrator.dto.CloudProvider;
import it.reply.orchestrator.dto.RankCloudProvidersMessage;
import it.reply.orchestrator.dto.slam.Service;
import it.reply.orchestrator.dto.slam.Sla;
import it.reply.orchestrator.service.SlamService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class GetSlam extends BaseRankCloudProvidersCommand {

  @Autowired
  private SlamService slamService;

  @Override
  protected RankCloudProvidersMessage
      customExecute(RankCloudProvidersMessage rankCloudProvidersMessage) {
    rankCloudProvidersMessage.setSlamPreferences(slamService.getCustomerPreferences());

    // Get VO (customer) preferences and SLAs (infer available Cloud Providers from it)
    for (Sla sla : rankCloudProvidersMessage.getSlamPreferences().getSla()) {
      // Create Cloud Provider, add to the list
      CloudProvider cp = new CloudProvider(sla.getProvider());
      rankCloudProvidersMessage.getCloudProviders().put(sla.getProvider(), cp);

      // Get provider's services
      for (Service service : sla.getServices()) {
        cp.getCmdbProviderServices().put(service.getServiceId(), null);
      }
    }

    return rankCloudProvidersMessage;
  }

}

@@ -593,23 +593,16 @@
 sMessage
-%0D%0A     
  customE
@@ -608,16 +608,24 @@
 Execute(
+%0D%0A      
 RankClou
@@ -1004,16 +1004,125 @@
 der cp =
+ rankCloudProvidersMessage.getCloudProviders().get(sla.getProvider());%0D%0A      if (cp == null) %7B%0D%0A        cp =
  new Clo
@@ -1149,24 +1149,26 @@
 ovider());%0D%0A
+  
       rankCl
@@ -1235,16 +1235,25 @@
 ), cp);%0D
+%0A      %7D%0D
 %0A%0D%0A     

Support multiple SLAs for cloud providers