package com.purui.prims.headless.server.utils;

import com.purui.prims.common.util.BeanMapper;
import com.purui.prims.dscheduler.enums.Flag;
import com.purui.prims.dscheduler.enums.Priority;
import com.purui.prims.dscheduler.enums.TimeoutFlag;
import com.purui.prims.dscheduler.model.DSTaskRequest;
import com.purui.prims.dscheduler.model.TaskDefinition;
import com.purui.prims.dscheduler.model.TaskRequest;

/**
 * Scheduler任务对象转换
 *
 * @author charlie
 * @date 2024/7/15
 */
public class SchedulerConverter {

    public static TaskRequest converter(DSTaskRequest dsTaskRequest) {
        TaskRequest taskRequest = new TaskRequest();
        BeanMapper.mapper(dsTaskRequest, taskRequest);
        return taskRequest;
    }

    public static TaskRequest converter(TaskDefinition taskDefinition) {
        TaskRequest taskRequest = new TaskRequest();
        BeanMapper.mapper(taskDefinition, taskRequest);
        return taskRequest;
    }

    public static TaskDefinition converterToDefinition(TaskRequest task) {
        TaskDefinition newTask = new TaskDefinition();
        BeanMapper.mapper(task, newTask);
        newTask.setIsCache(Flag.valueOf(task.getIsCache()));
        newTask.setFlag(Flag.valueOf(task.getFlag()));
        newTask.setTaskPriority(Priority.valueOf(task.getTaskPriority()));
        newTask.setTimeoutFlag(TimeoutFlag.valueOf(task.getTimeoutFlag()));
        return newTask;
    }
}
