package com.lanyuanxiaoyao.service.scheduler.configuration;

import com.lanyuanxiaoyao.service.scheduler.quartz.compaction.*;
import com.lanyuanxiaoyao.service.scheduler.strategy.ScheduleStrategy;
import com.lanyuanxiaoyao.service.scheduler.strategy.ScheduleStrategyImpl;
import com.lanyuanxiaoyao.service.scheduler.strategy.ScheduleStrategyVO;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ZhangJiacheng
 * @date 2023-06-06
 */
@Configuration
public class ScheduleStrategyProvider {
    @Bean
    public ImmutableList<ScheduleStrategy> strategies() {
        return Lists.immutable.of(
                ScheduleStrategyImpl.simple(false, "distribute_schedule", "定时分布式调度", DistributeScheduleJob.class, "0/2 * * * * ?"),
                // 普通调度
                ScheduleStrategyImpl.simple("daily_schedule", "普通全表调度", DailyScheduleJob.class, "0 50 1,4,7,10,13,16,19 * * ?"),
                // 重点表调度
                ScheduleStrategyImpl.simple("focus_evening_schedule", "晚间重点表调度", FocusScheduleJob.class, "0 50 20,21,22 * * ?"),
                // ODS重点表调度
                ScheduleStrategyImpl.simple("ods_focus_schedule", "ODS 重点表调度", OdsFocusScheduleJob.class, "0 30 23 * * ?"),
                // 忙时调度
                ScheduleStrategyImpl.simple("focus_schedule", "重点表跨天调度", FocusUnVersionUpdateScheduleJob.class, "0 0,10,20,40 0,1 * * ?"),
                ScheduleStrategyImpl.simple(false, "remove_scheduled", "跨天调度时及时删除已完成跨天的任务", RemoveScheduledJob.class, "0 * 0,1 * * ?")
        );
    }

    @Bean
    public ImmutableList<ScheduleStrategyVO> strategyVOS(ImmutableList<ScheduleStrategy> strategies) {
        return strategies
                .select(ScheduleStrategy::enable)
                .collect(ScheduleStrategyVO::new);
    }
}
