package me.qwq.doghouse;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import lombok.extern.slf4j.Slf4j;


@MapperScan("me.qwq.doghouse.dao")
@SpringBootApplication
@EnableAsync(proxyTargetClass=true)
@EnableScheduling
@EnableCaching(proxyTargetClass=true)
@EnableAspectJAutoProxy(exposeProxy = true)
@Slf4j
public class BlogApplication {
    
    static Boolean isDebug = null;
    
    public static boolean isDebug () {
        
        if (isDebug == null) {
            RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
            String runtimeMXBeanInputArguments = runtimeMXBean.getInputArguments().toString();
            log.debug("Runtime MXBean input arguments: {}", runtimeMXBeanInputArguments);
            isDebug = runtimeMXBeanInputArguments.contains("-agentlib:jdwp");
        }
        return isDebug;
    }
    
    public static void main(String[] args) throws Exception {
        boolean isDebug = isDebug();
        
        // 根据是否调试加载额外的 application-*.yml
        SpringApplication app = new SpringApplication(BlogApplication.class);
        String additionalProfiles = isDebug ? "debug" : "prod";
        app.setAdditionalProfiles(additionalProfiles);
        log.info("Current is {}debug, set additional profiles: {}", isDebug ? "" : "not ", additionalProfiles);
        app.run(args);
    }
}
