package com.keyware.shandan.frame.properties;

import com.keyware.shandan.common.enums.SystemTypes;
import com.keyware.shandan.frame.config.component.AppContext;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * 系统定义属性
 *
 * @author GuoXin
 * @since 2021/6/29
 */
@Data
@Configuration
@ConfigurationProperties("project")
public class CustomProperties {
    /**
     * 系统ID
     */
    private SystemTypes id;
    /**
     * 系统名称
     */
    private String appName;
    /**
     * 静态资源地址
     */
    private String staticResourceAddress = "";

    /**
     * 统一认证服务内网IP地址
     */
    private String oauthServerInternalIp = "";

    /**
     * 是否启用验证码
     */
    private Boolean captchaEnable = false;
    /**
     * 是否启用记住我
     */
    private Boolean rememberMeEnable = false;

    /**
     * 文件存储配置
     */
    private FileStorageProperties fileStorage = new FileStorageProperties();

    public static CustomProperties staticInstance() {
        return AppContext.getContext().getBean(CustomProperties.class);
    }
    public static FileStorageProperties getFileStorageProperty(){
        return staticInstance().getFileStorage();
    }

    /**
     * 文件存储配置属性
     */
    @Data
    public static class FileStorageProperties {
        /**
         * 文件存储路径
         */
        private String path = System.getProperty("user.home") + "/shandan";
        /**
         * 临时文件存放路径
         */
        private String tempPath = path + "/temp";

        /**
         * 驱动程序上传存放路径
         */
        private String jarPath = path + "/jar";

        /**
         * 上传文件web访问前缀
         */
        private String uploadPathWebUriPrefix = "/upload";

        /**
         * 文件服务映射别名
         */
        private String uploadFileMapper = uploadPathWebUriPrefix + "/**";
    }
}
