package com.aip.gateway.api.config;

import com.aip.gateway.api.utils.SysUtils;
import jakarta.annotation.PostConstruct;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.io.File;

@Slf4j
@Getter
@Setter
@ToString
@Configuration
@ConfigurationProperties(prefix = "application")
public class ApplicationConfig {

    private int aipServerId = 0;
    private int availableProcessors = 8;

    private String bootingDateTime;
    private boolean startSchedule;

    @PostConstruct
    private void init() {
        this.startSchedule = false;
        this.availableProcessors  = Runtime.getRuntime().availableProcessors() * 2;
        this.bootingDateTime = SysUtils.getSysTimeStr();
        log.info("{}", this);
    }

    public boolean makeDirectory(String path, String desc) {
        boolean result = false;
        File folder = new File(path);
        if (!folder.exists()) {
            try {
                result = folder.mkdir(); //폴더 생성.
                log.info("{}, ({}) created.", folder.getAbsolutePath(), desc);
            }
            catch(Exception e) {
                log.error("{}, ({}) create failed. {}.", folder.getAbsolutePath(), desc, e.getMessage());
            }
        }
        return result;
    }

}
