package sg.ncl;

import org.springframework.boot.context.properties.ConfigurationProperties;
import sg.ncl.testbed_interface.TeamStatus;

/**
 * Created by Te Ye
 */
@ConfigurationProperties(prefix = ConnectionProperties.PREFIX)
public class ConnectionProperties {

    public static final String PREFIX = "ncl.web.service";

    private String sioAddress;
    private String sioPort;
    private String authEndpoint;
    private String credEndpoint;
    private String regEndpoint;
    private String userEndpoint;
    private String teamEndpoint;
    private String teamVisibilityEndpoint;
    private String expEndpoint;
    private String approveJoinRequest;
    private String realEndpoint;

    public String getSioAddress() {
        return sioAddress;
    }

    public void setSioAddress(String sioAddress) {
        this.sioAddress = sioAddress;
    }

    public String getSioPort() {
        return sioPort;
    }

    public void setSioPort(String sioPort) {
        this.sioPort = sioPort;
    }

    public String getAuthEndpoint() {
        return authEndpoint;
    }

    public void setAuthEndpoint(String authEndpoint) {
        this.authEndpoint = authEndpoint;
    }

    public String getCredEndpoint() {
        return credEndpoint;
    }

    public void setCredEndpoint(String credEndpoint) {
        this.credEndpoint = credEndpoint;
    }

    public String getRegEndpoint() {
        return regEndpoint;
    }

    public void setRegEndpoint(String regEndpoint) {
        this.regEndpoint = regEndpoint;
    }

    public String getUserEndpoint() {
        return userEndpoint;
    }

    public void setUserEndpoint(String userEndpoint) {
        this.userEndpoint = userEndpoint;
    }

    public String getTeamEndpoint() {
        return teamEndpoint;
    }

    public void setTeamEndpoint(String teamEndpoint) {
        this.teamEndpoint = teamEndpoint;
    }

    public String getExpEndpoint() {
        return expEndpoint;
    }

    public void setExpEndpoint(String expEndpoint) {
        this.expEndpoint = expEndpoint;
    }

    public String getRealEndpoint() {
        return realEndpoint;
    }

    public void setRealEndpoint(String realEndpoint) {
        this.realEndpoint = realEndpoint;
    }

    public String getSioUsersUrl() {
        return "http://" + sioAddress + ":" + sioPort + "/" + userEndpoint + "/";
    }

    public String getSioTeamsUrl() {
        return "http://" + sioAddress + ":" + sioPort + "/" + teamEndpoint + "/";
    }

    public String getSioAuthUrl() {
        return "http://" + sioAddress + ":" + sioPort + "/" + authEndpoint + "/";
    }

    public String getSioCredUrl() {
        return "http://" + sioAddress + ":" + sioPort + "/" + credEndpoint + "/";
    }

    public String getSioRegUrl() {
        return "http://" + sioAddress + ":" + sioPort + "/" + regEndpoint + "/";
    }

    public String getTeamVisibilityEndpoint() {
        return teamVisibilityEndpoint;
    }

    public void setTeamVisibilityEndpoint(String teamVisibilityEndpoint) {
        this.teamVisibilityEndpoint = teamVisibilityEndpoint;
    }

    public String getSioExpUrl() {
        return "http://" + sioAddress + ":" + sioPort + "/" + expEndpoint + "/";
    }

    public String getDeleteExperiment(String expId) {
        return "http://" +  sioAddress + ":" + sioPort + "/" + expEndpoint + "/delete/" + expId;
    }

    public String getStartExperiment(String teamName, String expId) {
        return "http://" + sioAddress + ":" + sioPort + "/" + realEndpoint + "/start/team/" + teamName + "/experiment/" + expId;
    }

    public String getStopExperiment(String teamName, String expId) {
        return "http://" +  sioAddress + ":" + sioPort + "/" + realEndpoint + "/stop/team/" + teamName + "/experiment/" + expId;
    }

    public String getApproveJoinRequest(String teamId, String userId) {
        return "http://" + sioAddress + ":" + sioPort + "/" + regEndpoint + "/teams/" + teamId + "/members/" + userId;
    }

    public void setApproveJoinRequest(String approveJoinRequest) {
        this.approveJoinRequest = approveJoinRequest;
    }

    public String getRejectJoinRequest(String teamId, String userId) {
        // same but REST API is DELETE
        return "http://" + sioAddress + ":" + sioPort + "/" + regEndpoint + "/teams/" + teamId + "/members/" + userId;
    }

    // for existing users
    public String getRegisterRequestToApplyTeam(String nclUserId) {
        return "http://" + sioAddress + ":" + sioPort + "/" + regEndpoint + "/newTeam/" + nclUserId;
    }

    public String getApproveTeam(String teamId, String ownerId, TeamStatus teamStatus) {
        return "http://" + sioAddress + ":" + sioPort + "/" + regEndpoint + "/teams/" + teamId + "/owner/" + ownerId + "?status=" + teamStatus;
    }

    public String getExpListByTeamId(String teamId) {
        return "http://" + sioAddress + ":" + sioPort + "/" + expEndpoint + "/teams/" + teamId;
    }

    public String getRealization(String expId) {
        return "http://" + sioAddress + ":" + sioPort + "/" + realEndpoint + "/" + expId;
    }

    public String getDeterUid(String id) {
        return "http://" + sioAddress + ":" + sioPort + "/" + regEndpoint + "/user/" + id;
    }
}


@@ -2482,32 +2482,181 @@
 t + %22/%22;%0A    %7D%0A%0A
+    public String getTeamByName(String name) %7B%0A        return %22http://%22 + sioAddress + %22:%22 + sioPort + %22/%22 + teamEndpoint + %22/?name=%22 + name;%0A    %7D%0A%0A
     public Strin

add new endpoint