package com.tofly.common.config;

import com.tofly.base.api.feign.FlowableService;
import com.tofly.common.oauth.handler.AutoUploadForm;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
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;

import javax.annotation.Resource;

/**
 * @author tuonbed
 * @date 2020/5/29  10:06
 */
@Configuration
@ConditionalOnClass(AutoUploadForm.class)
@EnableConfigurationProperties(UploadAutoProperties.class)
public class UploadAutoConfiguration {

    @Resource
    private UploadAutoProperties uploadAutoProperties;
    @Resource
    private FlowableService flowableService;


    @Bean
    @ConditionalOnMissingBean(AutoUploadForm.class)
    @ConditionalOnProperty(prefix = "tofly.flupload",value = "enable",havingValue = "true")
    public AutoUploadForm autoUploadForm(){
        AutoUploadForm autoUploadForm=new AutoUploadForm();
        autoUploadForm.setAppName(uploadAutoProperties.getAppName());
        autoUploadForm.setFlowableService(flowableService);
        return autoUploadForm;
    }
}
