/*
 * Copyright 2017 flow.ci
 *
 * 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 com.flow.platform.api.util;

/**
 * @author yh@firim
 */

public class PlatformURL {

    private String cmdUrl;

    private String queueUrl;

    private String agentUrl;

    private String agentSettingsUrl;

    private String sysInfoUrl;

    private String sysIndexUrl;

    private String agentCreateUrl;

    private String cmdDownloadLogUrl;

    public PlatformURL(String baseURL) {
        queueUrl = String.format("%s%s", baseURL, "cmd/queue/send");

        cmdUrl = String.format("%s%s", baseURL, "cmd/send");
        cmdDownloadLogUrl = String.format("%s%s", baseURL, "cmd/log/download");

        sysIndexUrl = String.format("%s%s", baseURL, "index");
        sysInfoUrl = String.format("%s%s", baseURL, "sys/info");

        agentUrl = String.format("%s%s", baseURL, "agents/list");
        agentCreateUrl = String.format("%s%s", baseURL, "agents/create");
        agentSettingsUrl = String.format("%s%s", baseURL, "agents/settings");
    }

    public String getAgentCreateUrl() {
        return agentCreateUrl;
    }

    public String getAgentSettingsUrl() {
        return agentSettingsUrl;
    }

    public String getCmdUrl() {
        return cmdUrl;
    }

    public String getQueueUrl() {
        return queueUrl;
    }

    public String getCmdDownloadLogUrl() {
        return cmdDownloadLogUrl;
    }

    public String getAgentUrl() {
        return agentUrl;
    }

    public String getSysIndexUrl() {
        return sysIndexUrl;
    }

    public String getSysInfoUrl() {
        return sysInfoUrl;
    }

    @Override
    public String toString() {
        return "PlatformURL{" +
            "cmdUrl='" + cmdUrl + '\'' +
            ", queueUrl='" + queueUrl + '\'' +
            ", agentUrl='" + agentUrl + '\'' +
            ", agentSettingsUrl='" + agentSettingsUrl + '\'' +
            ", sysInfoUrl='" + sysInfoUrl + '\'' +
            ", sysIndexUrl='" + sysIndexUrl + '\'' +
            ", agentCreateUrl='" + agentCreateUrl + '\'' +
            ", cmdDownloadLogUrl='" + cmdDownloadLogUrl + '\'' +
            '}';
    }
}

@@ -621,16 +621,61 @@
 .util;%0A%0A
+import com.flow.platform.util.http.HttpURL;%0A%0A
 /**%0A * @
@@ -727,32 +727,38 @@
  %7B%0A%0A    private 
+final 
 String cmdUrl;%0A%0A
@@ -765,24 +765,30 @@
     private 
+final 
 String queue
@@ -797,32 +797,38 @@
 l;%0A%0A    private 
+final 
 String agentUrl;
@@ -833,32 +833,38 @@
 l;%0A%0A    private 
+final 
 String agentSett
@@ -877,32 +877,38 @@
 l;%0A%0A    private 
+final 
 String sysInfoUr
@@ -919,24 +919,30 @@
     private 
+final 
 String sysIn
@@ -958,24 +958,30 @@
     private 
+final 
 String agent
@@ -1004,16 +1004,22 @@
 private 
+final 
 String c
@@ -1101,39 +1101,38 @@
 l = 
-String.format(%22%25s%25s%22, baseURL, 
+HttpURL.build(baseURL).append(
 %22cmd
@@ -1144,18 +1144,28 @@
 e/send%22)
+.toString()
 ;
-%0A
 %0A       
@@ -1178,111 +1178,120 @@
 l = 
-String.format(%22%25s%25s%22, baseURL, %22cmd/send%22);%0A        cmdDownloadLogUrl = String.format(%22%25s%25s%22, baseURL, 
+HttpURL.build(baseURL).append(%22cmd/send%22).toString();%0A        cmdDownloadLogUrl = HttpURL.build(baseURL).append(
 %22cmd
@@ -1305,16 +1305,27 @@
 wnload%22)
+.toString()
 ;%0A%0A     
@@ -1345,165 +1345,184 @@
 l = 
-String.format(%22%25s%25s%22, baseURL, %22index%22);%0A        sysInfoUrl = String.format(%22%25s%25s%22, baseURL, %22sys/info%22);%0A%0A        agentUrl = String.format(%22%25s%25s%22, baseURL, 
+HttpURL.build(baseURL).append(%22index%22).toString();%0A        sysInfoUrl = HttpURL.build(baseURL).append(%22sys/info%22).toString();%0A%0A        agentUrl = HttpURL.build(baseURL).append(
 %22age
@@ -1531,16 +1531,27 @@
 s/list%22)
+.toString()
 ;%0A      
@@ -1573,39 +1573,38 @@
 l = 
-String.format(%22%25s%25s%22, baseURL, 
+HttpURL.build(baseURL).append(
 %22age
@@ -1615,16 +1615,27 @@
 create%22)
+.toString()
 ;%0A      
@@ -1659,39 +1659,38 @@
 l = 
-String.format(%22%25s%25s%22, baseURL, 
+HttpURL.build(baseURL).append(
 %22age
@@ -1703,16 +1703,27 @@
 ttings%22)
+.toString()
 ;%0A    %7D%0A

refactor url by appling HttpURL builder