package com.aegis.emergency.dispatch.constant;

import org.apache.commons.lang3.StringUtils;
import lombok.Getter;

/**
 * 调度任务操作日志动作枚举
 *
 * 用于 dispatch_task_log.action 字段
 *
 * @author aegis
 */
@Getter
public enum DispatchTaskAction {

    // 任务操作
    TASK_CREATED("task_created", "创建任务"),
    TASK_UPDATED("task_updated", "更新任务"),
    TASK_PUBLISHED("task_published", "发布任务"),
    TASK_CLOSED("task_closed", "关闭任务"),

    // 参与方操作
    PARTICIPANT_ADDED("participant_added", "添加参与方"),

    // 资源操作
    RESOURCE_ALLOCATED("resource_allocated", "资源调配"),

    // 执行操作
    DISPOSAL_REPORTED("disposal_reported", "上报处置记录"),

    // 预留其他动作
    OTHER("other", "其他操作");

    private final String code;
    private final String label;

    DispatchTaskAction(String code, String label) {
        this.code = code;
        this.label = label;
    }

    /**
     * 根据代码获取枚举
     * 
     * @param code 代码
     * @return 枚举值，如果找不到则返回 null
     */
    public static DispatchTaskAction fromCode(String code) {
        if (StringUtils.isBlank(code)) {
            return null;
        }
        for (DispatchTaskAction action : values()) {
            if (action.code.equals(code)) {
                return action;
            }
        }
        return null;
    }
}