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;


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

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

    public static class URL {

        private static final String host = "http://42.192.195.253:30881";
        // s2i相关url
        public static final String S2I_BUILDER_URL = host + "/apis/devops.kubesphere.io/v1alpha1/namespaces/mkcloud/s2ibuilders";
        public static final String S2I_CREATE_BINARY_QUERY_URL = host + "/apis/devops.kubesphere.io/v1alpha1/namespaces/mkcloud/s2ibinaries";
        public static final String S2I_UPLOAD_FILE_QUERY_URL = host + "/kapis/devops.kubesphere.io/v1alpha2/namespaces/mkcloud/s2ibinaries/%s/file";
        public static final String S2I_RUN = host + "/apis/devops.kubesphere.io/v1alpha1/namespaces/mkcloud/s2iruns";
        // 存储卷相关url
        public static final String STORAGE_VOLUME_CREATE = host + "/api/v1/namespaces/mkcloud/persistentvolumeclaims";
        // 应用相关
        public static final String APPLICATION_DRY_RUN = host + "/apis/app.k8s.io/v1beta1/namespaces/mkcloud/applications?dryRun=All";
        public static final String INGRESS_DRY_RUN = host + "/apis/extensions/v1beta1/namespaces/mkcloud/ingresses?dryRun=All";
        public static final String DEPLOYMENT_DRY_RUN = host + "/apis/apps/v1/namespaces/mkcloud/deployments?dryRun=All";
        public static final String SERVICE_DRY_RUN = host + "/api/v1/namespaces/mkcloud/services?dryRun=All";
        public static final String APPLICATION = host + "/apis/app.k8s.io/v1beta1/namespaces/mkcloud/applications";
        public static final String INGRESS = host + "/apis/extensions/v1beta1/namespaces/mkcloud/ingresses";
        public static final String DEPLOYMENT = host + "/apis/apps/v1/namespaces/mkcloud/deployments";
        public static final String SERVICE = host + "/api/v1/namespaces/mkcloud/services";
        // token
        public static final String OAUTH_TOKEN = host + "/oauth/token";
    }

//    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();
    }
}
