package com.aegis.emergency.alert.constant;

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

/**
 * 警情操作日志动作枚举
 *
 * 用于 duty_alert_log.action 字段
 *
 * @author aegis
 */
@Getter
public enum AlertLogAction {

    ALERT_CREATE("alert_create", "创建警情"),
    ALERT_UPDATE("alert_update", "更新警情"),
    ALERT_RECEIVED("alert_received", "已接警"),
    ALERT_TRANSFERRED("alert_transferred", "已转警"),
    ALERT_CONVERTED("alert_converted", "已转事件"),
    ALERT_CLOSE("alert_close", "已关闭"),

    TRANSFER_APPLY("transfer_apply", "提交转警申请"),
    TRANSFER_APPROVE("transfer_approve", "转警审核通过"),
    TRANSFER_REJECT("transfer_reject", "转警审核驳回"),
    TRANSFER_FEEDBACK("transfer_feedback", "转警反馈登记"),
    TRANSFER_PROCESSED("transfer_processed", "转警处理完成"),

    CONVERT_APPLY("convert_apply", "提交转事件申请"),
    CONVERT_APPROVE("convert_approve", "转事件审核通过"),
    CONVERT_REJECT("convert_reject", "转事件审核驳回"),
    CONVERT_EVENT_CREATED("convert_event_created", "转事件创建事件"),

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

    private final String code;
    private final String label;

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

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