package com.ruoyi.project.config;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * /**
 *
 * @author fangk
 * @date 2024/5/28
 * @desc AppConfig 应用配置
 */

@Configuration
@ConfigurationProperties(prefix = "app")
@Data
@Slf4j
public class AppConfig implements InitializingBean {

    // 不要有多个静态变量，否则注入可能失败
    private static String dataFolder;
    private static String recycleFolder;
    // private String uploadFolder;

    public static String getDataFolder() {
        return dataFolder;
    }

    public void setDataFolder(String dataFolder) {
        AppConfig.dataFolder = dataFolder;
    }

    public static String getRecycleFolder() {
        return recycleFolder;
    }

    public void setRecycleFolder(String recycleFolder) {
        AppConfig.recycleFolder = recycleFolder;
    }

    public static String getRecyclePath() {
        return dataFolder.endsWith("/") ? dataFolder + recycleFolder : dataFolder + "/" + recycleFolder;
    }

    // or @PostConstruct
    @Override
    public void afterPropertiesSet() throws Exception {
        // // 校验配置是否存在
        // if (dataFolder == null) {
        //     log.error("资料库根目录未配置");
        //     // throw new RuntimeException("dataFolder is null");
        // }
        // if (recycleFolder == null) {
        //     log.error("回收站目录未配置");
        // }
    }

}