package com.syjy.calculate.config;

import com.syjy.calculate.conotroller.JarCalculate;
import com.syjy.calculate.conotroller.Test;
import com.syjy.calculate.listener.ApplicationListenerImpl;
import com.syjy.calculate.repository.repositoryImpl.CalculationFormulaRepositoryImpl;
import com.syjy.calculate.service.AccuracyPassRateCalculateService;
import com.syjy.calculate.service.AssessmentCalculateService;
import com.syjy.calculate.util.Common;
import com.syjy.calculate.util.CreateAndInsertSqlUtil;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@EnableConfigurationProperties(StarterProperties.class)
@Configuration

/**
 * 配置自动化装配类
 *
 * @author zcl
 * @version 1.0
 * @since 2022/8/8 9:30
 */
public class StarterAutoConfigure {

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "calculate.service", value = "enabled", havingValue = "true")
    AccuracyPassRateCalculateService accuracyPassRateCalculateService() {
        return new AccuracyPassRateCalculateService();
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "calculate.service", value = "enabled", havingValue = "true")
    AssessmentCalculateService assessmentCalculateService() {
        return new AssessmentCalculateService();
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "calculate.service", value = "enabled", havingValue = "true")
    CalculationFormulaRepositoryImpl calculationFormulaRepositoryImpl() {
        return new CalculationFormulaRepositoryImpl();
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "calculate.service", value = "enabled", havingValue = "true")
    ApplicationListenerImpl applicationListenerImpl() {
        return new ApplicationListenerImpl();
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "calculate.service", value = "enabled", havingValue = "true")
    CreateAndInsertSqlUtil CreateAndInsertSqlUtil() {
        return new CreateAndInsertSqlUtil();
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "calculate.service", value = "enabled", havingValue = "true")
    Common CommonUtil() {
        return new Common();
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "calculate.service", value = "enabled", havingValue = "true")
    Test test() {
        return new Test();
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "calculate.service", value = "enabled", havingValue = "true")
    JarCalculate jarCalculate() {
        return new JarCalculate();
    }

}