package com.tiesheng.core.config.global;

import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * @author hao
 */
@Configuration
@ConfigurationProperties(prefix = "tiesheng.global")
public class GlobalConfig {

    private String host;
    private String service;
    private String version;

    ///////////////////////////////////////////////////////////////////////////
    // 逻辑方法
    ///////////////////////////////////////////////////////////////////////////

    public String getContextPath() {
        String context = SpringUtil.getProperty("server.servlet.context-path");
        if (StrUtil.isEmpty(context)) {
            context = "";
        }
        return context;
    }


    /**
     * 构建完整的路径
     *
     * @param path
     * @return
     */
    public String buildPath(String path) {
        if (StrUtil.isEmpty(path)) {
            path = "";
        }
        if (!StrUtil.isEmpty(host) && !StrUtil.startWith(path, "http")) {
            path = host + getContextPath() + path;
        }
        return path;
    }

    ///////////////////////////////////////////////////////////////////////////
    // setter\getter
    ///////////////////////////////////////////////////////////////////////////

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getService() {
        return service;
    }

    public void setService(String service) {
        this.service = service;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }
}
