
package cn.orionsec.ops.handler.scheduler;

import cn.orionsec.kit.lang.able.SafeCloseable;
import cn.orionsec.kit.lang.function.select.Branches;
import cn.orionsec.kit.lang.function.select.Selector;
import cn.orionsec.ops.constant.common.SerialType;

public interface ITaskProcessor extends Runnable, SafeCloseable {

    /**
     * 停止全部
     */
    void terminateAll();

    /**
     * 停止机器操作
     *
     * @param recordMachineId recordMachineId
     */
    void terminateMachine(Long recordMachineId);

    /**
     * 跳过机器操作
     *
     * @param recordMachineId recordMachineId
     */
    void skipMachine(Long recordMachineId);

    /**
     * 发送机器命令
     *
     * @param recordMachineId recordMachineId
     * @param command         command
     */
    void writeMachine(Long recordMachineId, String command);

    /**
     * 获取实际执行处理器
     *
     * @param recordId recordId
     * @param type     type
     * @return 处理器
     */
    static ITaskProcessor with(Long recordId, SerialType type) {
        return Selector.<SerialType, ITaskProcessor>of(type)
                .test(Branches.eq(SerialType.SERIAL)
                        .then(() -> new SerialTaskProcessor(recordId)))
                .test(Branches.eq(SerialType.PARALLEL)
                        .then(() -> new ParallelTaskProcessor(recordId)))
                .get();
    }

}
