package com.citygis.common.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 读取项目相关配置
 *
 * @author citygis
 */
@Component
@ConfigurationProperties(prefix = "citygis")
public class CitygisConfig {

    /**
     * windows上传路径
     */
    private static String windows_profile;

    /**
     * Linux上传路径
     */
    private static String linux_profile;


    public static String getSystemType() throws Exception {
        String osName = System.getProperty("os.name").toLowerCase();

        if (osName.contains("win")) {
            return getWindows_profile();
        } else if (osName.contains("nix") || osName.contains("nux") || osName.contains("mac")) {
            return getLinux_profile();
        } else {
            return "unknown";
        }
    }

    /**
     * 项目名称
     */
    private String name;

    /**
     * 版本
     */
    private String version;

    /**
     * 版权年份
     */
    private String copyrightYear;


    /**
     * 获取地址开关
     */
    private static boolean addressEnabled;

    /**
     * 验证码类型
     */
    private static String captchaType;

    /**
     * 上传路径
     */
    private static String profile;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getVersion() {
        return version;
    }

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

    public String getCopyrightYear() {
        return copyrightYear;
    }

    public void setCopyrightYear(String copyrightYear) {
        this.copyrightYear = copyrightYear;
    }

    public static String getProfile() {
        return profile;
    }

    public void setProfile(String profile) {
        com.citygis.common.config.CitygisConfig.profile = profile;
    }

    public static boolean isAddressEnabled() {
        return addressEnabled;
    }

    public void setAddressEnabled(boolean addressEnabled) {
        com.citygis.common.config.CitygisConfig.addressEnabled = addressEnabled;
    }

    public static String getCaptchaType() {
        return captchaType;
    }

    public void setCaptchaType(String captchaType) {
        com.citygis.common.config.CitygisConfig.captchaType = captchaType;
    }

    public static String getWindows_profile() {
        return windows_profile;
    }

    public void setWindows_profile(String windows_profile) {
        com.citygis.common.config.CitygisConfig.windows_profile = windows_profile;
    }

    public static String getLinux_profile() {
        return linux_profile;
    }

    public void setLinux_profile(String linux_profile) {
        com.citygis.common.config.CitygisConfig.linux_profile = linux_profile;
    }

    /**
     * 获取导入上传路径
     */
    public static String getImportPath() throws Exception {
        return getSystemType() + "/import";
    }

    /**
     * 获取头像上传路径
     */
    public static String getAvatarPath() throws Exception {
        return getSystemType() + "/avatar";
    }

    /**
     * 获取下载路径
     */
    public static String getDownloadPath() throws Exception {
        return getSystemType() + "/download/";
    }

    /**
     * 获取上传路径
     */
    public static String getUploadPath() throws Exception {
        return getSystemType() + "/upload";
    }

}
