package com.aegis.emergency.event.constant;

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

/**
 * 事件操作日志动作枚举
 *
 * 用于 event_log.action 字段
 *
 * @author aegis
 */
@Getter
public enum EventAction {

    EVENT_CREATED("event_created", "创建事件"),
    EVENT_UPDATED("event_updated", "更新事件"),
    STATUS_CHANGE("status_changed", "状态变更"),
    DISPATCH_LINKED("dispatch_linked", "关联调度任务"),
    REPORT("report", "上报"),
    FOLLOW_UP_REPORT("follow_up_report", "续报"),
    EVENT_PINNED("event_pinned", "标记为重点"),
    EVENT_UNPINNED("event_unpinned", "取消重点"),
    EVENT_DELETED("event_deleted", "删除事件"),

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

    private final String code;
    private final String label;

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

    public static EventAction fromCode(String code) {
        if (StringUtils.isBlank(code)) {
            return null;
        }
        for (EventAction action : values()) {
            if (action.code.equals(code)) {
                return action;
            }
        }
        return null;
    }
}