package cn.axzo.workflow.core.conf;

import cn.axzo.workflow.core.engine.job.service.CustomTimerJobEntityManagerImpl;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.impl.AbstractEngineConfiguration;
import org.flowable.common.engine.impl.EngineConfigurator;
import org.flowable.job.service.JobServiceConfiguration;
import org.flowable.spring.SpringProcessEngineConfiguration;

/**
 * 自定义的任务服务的配置类
 *
 * @author wangli
 * @since 2025-03-12 14:18
 */
@Slf4j
public class CustomJobServiceConfiguration implements EngineConfigurator {

    @Override
    public void beforeInit(AbstractEngineConfiguration engineConfiguration) {

    }

    @Override
    public void configure(AbstractEngineConfiguration engineConfiguration) {
        if (!(engineConfiguration instanceof SpringProcessEngineConfiguration)) {
            return;
        }
        JobServiceConfiguration jobServiceConfiguration = ((SpringProcessEngineConfiguration) engineConfiguration).getJobServiceConfiguration();
        jobServiceConfiguration.setTimerJobEntityManager(new CustomTimerJobEntityManagerImpl(jobServiceConfiguration, jobServiceConfiguration.getTimerJobDataManager()));
    }

    @Override
    public int getPriority() {
        return 0;
    }
}
