package com.bs.common.config;

import com.bs.common.utils.OsInfoUtil;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * 读取项目相关配置
 *
 * @author bs
 */
@Component
@ConfigurationProperties(prefix = "bs")
public class BsConfig
{
    /** 项目名称 */
    private String name;

    /**
     * 维护租户列名称
     */
    private static String column = "tenant_id";

    /**
     * 多租户的数据表集合（不忽略的表）
     */
    private static Set<String> noIgnoreTables;
    /** 版本 */
    private String version;

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

    /** 实例演示开关 */
    private boolean demoEnabled;

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

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

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

    /**
     * windows附件地址
     */
    private static String winLocalFilePath;
    /**
     * linux附件地址
     */
    private static String linuxLocalFilePath;
    /**
     * mac附件地址
     */
    private static String macLocalFilePath;

    public void setWinLocalFilePath(String winLocalFilePath) {
        BsConfig.winLocalFilePath = winLocalFilePath;
    }

    public void setLinuxLocalFilePath(String linuxLocalFilePath) {
        BsConfig.linuxLocalFilePath = linuxLocalFilePath;
    }

    public void setMacLocalFilePath(String macLocalFilePath) {
        BsConfig.macLocalFilePath = macLocalFilePath;
    }

    public static String getWinLocalFilePath() {
        return winLocalFilePath;
    }

    public static String getLinuxLocalFilePath() {
        return linuxLocalFilePath;
    }
    public static String getMacLocalFilePath() {
        return macLocalFilePath;
    }



    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 boolean isDemoEnabled()
    {
        return demoEnabled;
    }

    public void setDemoEnabled(boolean demoEnabled)
    {
        this.demoEnabled = demoEnabled;
    }

    public static String getProfile()
    {
        return profile;
    }

    public void setProfile(String profile)
    {
        BsConfig.profile = profile;
    }

    public static String getColumn() {
        return column;
    }

    public static void setColumn(String column) {
        BsConfig.column = column;
    }
    public static Set<String> getTables() {
        return getNoIgnoreTables();
    }
    public static Set<String> getNoIgnoreTables() {
        return noIgnoreTables;
    }

    public static void setNoIgnoreTables(Set<String> noIgnoreTables) {
        BsConfig.noIgnoreTables = noIgnoreTables;
    }

    public static boolean isAddressEnabled()
    {
        return addressEnabled;
    }

    public void setAddressEnabled(boolean addressEnabled)
    {
        BsConfig.addressEnabled = addressEnabled;
    }

    public static String getCaptchaType() {
        return captchaType;
    }

    public void setCaptchaType(String captchaType) {
        BsConfig.captchaType = captchaType;
    }

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

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

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

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


    /**
     * 根据系统切换存放附件绝对地址
     *
     * @return 存放附件绝对地址
     */
    public static String getFilePath() {
        if (OsInfoUtil.isLinux()) {
            return getLinuxLocalFilePath();
        }
        if (OsInfoUtil.isMacOS() || OsInfoUtil.isMacOSX()) {
            return getMacLocalFilePath();
        }
        return getWinLocalFilePath();
    }

}
