package io.renren.modules.kubesphere.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.sql.SQLOutput;


/**
 * @author chenrj
 * @email 1412736935@qq.com
 * @since 2021/7/29
 */
@Configuration
public class KubeSphereConfig {
    public static String kubesphereUrl;
    public static String host;

    // s2i相关url
    public static String S2I_BUILDER_URL;
    public static String S2I_CREATE_BINARY_QUERY_URL;
    public static String S2I_UPLOAD_FILE_QUERY_URL;
    public static String S2I_RUN;
    // 存储卷相关url
    public static String STORAGE_VOLUME_CREATE;
    // 应用相关
    public static String APPLICATION_DRY_RUN;
    public static String INGRESS_DRY_RUN;
    public static String DEPLOYMENT_DRY_RUN;
    public static String SERVICE_DRY_RUN;
    public static String APPLICATION;
    public static String INGRESS;
    public static String DEPLOYMENT;
    public static String SERVICE;
    // token
    public static String OAUTH_TOKEN;

    @Value("${kubesphereUrl}")
    public void setS2iBuilderUrl(String kubesphereUrl) {
        KubeSphereConfig.S2I_BUILDER_URL = kubesphereUrl + "/apis/devops.kubesphere.io/v1alpha1/namespaces/mkcloud/s2ibuilders";
    }
    @Value("${kubesphereUrl}")
    public void setS2iCreateBinaryQueryUrl(String kubesphereUrl) {
        KubeSphereConfig.S2I_CREATE_BINARY_QUERY_URL = kubesphereUrl + "/apis/devops.kubesphere.io/v1alpha1/namespaces/mkcloud/s2ibinaries";
    }
    @Value("${kubesphereUrl}")
    public void setS2iUploadFileQueryUrl(String kubesphereUrl) {
        KubeSphereConfig.S2I_UPLOAD_FILE_QUERY_URL = kubesphereUrl + "/kapis/devops.kubesphere.io/v1alpha2/namespaces/mkcloud/s2ibinaries/%s/file";
    }
    @Value("${kubesphereUrl}")
    public void setS2iRun(String kubesphereUrl) {
        KubeSphereConfig.S2I_RUN = kubesphereUrl + "/apis/devops.kubesphere.io/v1alpha1/namespaces/mkcloud/s2iruns";
    }

    @Value("${kubesphereUrl}")
    public void setStorageVolumeCreate(String kubesphereUrl) {
        KubeSphereConfig.STORAGE_VOLUME_CREATE = kubesphereUrl + "/api/v1/namespaces/mkcloud/persistentvolumeclaims";
    }

    @Value("${kubesphereUrl}")
    public void setApplicationDryRun(String kubesphereUrl) {
        KubeSphereConfig.APPLICATION_DRY_RUN = kubesphereUrl + "/apis/app.k8s.io/v1beta1/namespaces/mkcloud/applications?dryRun=All";
    }
    @Value("${kubesphereUrl}")
    public void setIngressDryRun(String kubesphereUrl) {
        KubeSphereConfig.INGRESS_DRY_RUN = kubesphereUrl + "/apis/extensions/v1beta1/namespaces/mkcloud/ingresses?dryRun=All";
    }
    @Value("${kubesphereUrl}")
    public void setDeploymentDryRun(String kubesphereUrl) {
        KubeSphereConfig.DEPLOYMENT_DRY_RUN = kubesphereUrl + "/apis/apps/v1/namespaces/mkcloud/deployments?dryRun=All";
    }
    @Value("${kubesphereUrl}")
    public void setServiceDryRun(String kubesphereUrl) {
        KubeSphereConfig.SERVICE_DRY_RUN = kubesphereUrl + "/api/v1/namespaces/mkcloud/services?dryRun=All";
    }
    @Value("${kubesphereUrl}")
    public void setAPPLICATION(String kubesphereUrl) {
        KubeSphereConfig.APPLICATION = kubesphereUrl + "/apis/app.k8s.io/v1beta1/namespaces/mkcloud/applications";
    }
    @Value("${kubesphereUrl}")
    public void setINGRESS(String kubesphereUrl) {
        KubeSphereConfig.INGRESS = kubesphereUrl + "/apis/extensions/v1beta1/namespaces/mkcloud/ingresses";
    }
    @Value("${kubesphereUrl}")
    public void setDEPLOYMENT(String kubesphereUrl) {
        KubeSphereConfig.DEPLOYMENT = kubesphereUrl + "/apis/apps/v1/namespaces/mkcloud/deployments";
    }
    @Value("${kubesphereUrl}")
    public void setSERVICE(String kubesphereUrl) {
        KubeSphereConfig.SERVICE = kubesphereUrl + "/api/v1/namespaces/mkcloud/services";
    }

    @Value("${kubesphereUrl}")
    public void setOauthToken(String kubesphereUrl) {
        KubeSphereConfig.OAUTH_TOKEN = kubesphereUrl + "/oauth/token";
    }

    @Value("${kubesphereUrl}")
    public void setKubesphereUrl(String kubesphereUrl) {
        KubeSphereConfig.kubesphereUrl = kubesphereUrl;
    }



//    public static class URL {



    //public static String host;

//        @Value("${kubesphereUrl}")
//        public void setHost(String host) {
//            URL.host = host;
//        }





//    }

    //    public static final String ORIGIN = "http://42.192.195.253:30881";
//    public static final String UA = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36";
//    public static final String REFERER = "http://42.192.195.253:30881";
//    public static final String ACCEPT = "*/*";
    public static String ORIGIN;
    @Value("${kubesphereUrl}")
    public static void setORIGIN(String ORIGIN) {
        KubeSphereConfig.ORIGIN = ORIGIN;
    }

    public static final String UA = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36";

    public static String REFERER = KubeSphereConfig.kubesphereUrl;
    @Value("${kubesphereUrl}")
    public static void setREFERER(String REFERER) {
        KubeSphereConfig.REFERER = REFERER;
    }

    public static final String ACCEPT = "*/*";

    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        // Do any additional configuration here
        return builder.build();
    }
}
