/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.quartz.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.quartz.SchedulerException;
import org.springblade.modules.quartz.entity.Job;
import org.springblade.modules.quartz.exception.TaskException;
import org.springblade.modules.quartz.vo.JobVO;

import java.util.List;

/**
 * 定时任务调度表 服务类
 *
 * @author BladeX
 * @since 2023-02-17
 */
public interface IJobService extends IService<Job> {

	/**
	 * 自定义分页
	 *
	 * @param page
	 * @param job
	 * @return
	 */
	IPage<JobVO> selectJobPage(IPage<JobVO> page, JobVO job);

	/**
	 * 获取quartz调度器的计划任务
	 *
	 * @param job 调度信息
	 * @return 调度任务集合
	 */
	List<Job> selectJobList(Job job);

	/**
	 * 通过调度任务ID查询调度信息
	 *
	 * @param jobId 调度任务ID
	 * @return 调度任务对象信息
	 */
	Job selectJobById(Long jobId);

	/**
	 * 暂停任务
	 *
	 * @param job 调度信息
	 * @return 结果
	 */
	int pauseJob(Job job) throws SchedulerException;

	/**
	 * 恢复任务
	 *
	 * @param job 调度信息
	 * @return 结果
	 */
	int resumeJob(Job job) throws SchedulerException;

	/**
	 * 删除任务后，所对应的trigger也将被删除
	 *
	 * @param job 调度信息
	 * @return 结果
	 */
	int deleteJob(Job job) throws SchedulerException;

	/**
	 * 批量删除调度信息
	 *
	 * @param jobIds 需要删除的任务ID
	 * @return 结果
	 */
	void deleteJobByIds(List<Long> jobIds) throws SchedulerException;

	/**
	 * 任务调度状态修改
	 *
	 * @param job 调度信息
	 * @return 结果
	 */
	int changeStatus(Job job) throws SchedulerException;

	/**
	 * 立即运行任务
	 *
	 * @param job 调度信息
	 * @return 结果
	 */
	boolean run(Job job) throws SchedulerException;

	/**
	 * 新增任务
	 *
	 * @param job 调度信息
	 * @return 结果
	 */
	int insertJob(Job job) throws SchedulerException, TaskException;

	/**
	 * 更新任务
	 *
	 * @param job 调度信息
	 * @return 结果
	 */
	int updateJob(Job job) throws SchedulerException, TaskException;

	/**
	 * 校验cron表达式是否有效
	 *
	 * @param cronExpression 表达式
	 * @return 结果
	 */
	boolean checkCronExpressionIsValid(String cronExpression);
}
