package com.utic.center.utic.ptis.server.config;

import com.utic.center.common.utils.TimeUtils;
import com.utic.center.utic.ptis.server.repository.ApplicationRepository;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Slf4j
@Getter
@Setter
@Component
@RequiredArgsConstructor
@ConfigurationProperties(prefix = "application")
public class ApplicationConfig {

    private String processName = "utic-ptis-server";
    private String processId = "70080";
    private int errTimeGap = 120;
    private int prcsThreadCount = 10;
    private int dbmsBatchSize = 1000;

    private String bootingTime;
    private boolean startSchedule;

    @PostConstruct
    private void init() {
        this.startSchedule = false;
        this.bootingTime = TimeUtils.now();

        if (this.dbmsBatchSize <= 1000) {
            this.dbmsBatchSize = 1000;
        }
        this.dbmsBatchSize = Math.min(this.dbmsBatchSize, 2000);

        ApplicationRepository.processState.setProcessId(this.processId);
        ApplicationRepository.processState.setErrTimeGap(this.getErrTimeGap());

        log.info("[{}] -------------------------", this.getClass().getSimpleName());
        log.info("{}", super.toString());
    }

}
