package org.interonet.gdm.Core;

import org.interonet.gdm.AuthenticationCenter.AuthToken;
import org.interonet.gdm.AuthenticationCenter.AuthTokenManager;
import org.interonet.gdm.AuthenticationCenter.IAuthTokenManager;

import java.util.Map;

public class GDMAgent implements IGDMAgent {
    GDMCore gdmCore;

    public GDMAgent(GDMCore gdmCore) {
        this.gdmCore = gdmCore;
    }

    @Override
    public String authenticateUser(String username, String password) {
        AuthToken authToken =  gdmCore.authenticateUser(username, password);
        return AuthTokenManager.toPlainText(authToken);
    }

    @Override
    public String getSwitchesUsageStatus(AuthToken authToken) {
        return gdmCore.getSwitchesUsageStatus(authToken);
    }

    @Override
    public String getVmsUsageStatus(AuthToken authToken) {
        return gdmCore.getVmsUsageStatus(authToken);
    }


    @Override
    public Boolean orderSlice(AuthToken authToken, int swichesNum, int vmsNum, String beginTime, String endTime,
                              Map<String, String> topology,
                              Map<String, String> switchConf,
                              String controllerIP, int controllerPort) {
        return gdmCore.orderSlice(authToken, swichesNum, vmsNum, beginTime, endTime, topology, switchConf, controllerIP, controllerPort);
    }

    @Override
    public String getOrdersList(AuthToken authToken) {
        return gdmCore.getOrdersIDList(authToken);
    }

    @Override
    public String getOrderInfoByID(AuthToken authToken, String orderID) {
        return gdmCore.getOrderInfoByID(authToken, orderID);
    }

    @Override
    public String deleteOrderByID(AuthToken authToken, String orderID) {
        return gdmCore.deleteOrderByID(authToken, orderID);
    }

    @Override
    public String getRunningSlice(AuthToken authToken) {
        return gdmCore.getRunningSliceIDsList(authToken);
    }

    @Override
    public IAuthTokenManager getAuthTokenManager() {
        return gdmCore.getAuthTokenManager();
    }

    @Override
    public String stopRunningSliceByID(AuthToken authToken, String orderID) {
        return gdmCore.stopRunningSliceByID(authToken, orderID);
    }
}

@@ -495,17 +495,16 @@
 hToken =
- 
  gdmCore
@@ -550,22 +550,40 @@
         
-return
+String authTokenPlainT =
  AuthTok
@@ -608,32 +608,101 @@
 ext(authToken);%0A
+        return authTokenPlainT != null ? authTokenPlainT : %22Failed%22;%0A
     %7D%0A%0A    @Over

return "Failed" when auth failed.