package cn.stylefeng.team.project.modular.filing.pojo.flux.enums;

import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.rule.base.ReadableEnum;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

@Getter
public enum FluxResponseTypeEnum implements ReadableEnum<FluxResponseTypeEnum> {

    ERROR(-1, "遇到错误"),

    SUCCESS_END(101, "GunsStreamFinish"),

    BUSINESS_LOG_CREATE(3000, "创建解析日志"),

    BEGIN_AI_INVOKE(3010, "开始调用大模型解析图片"),

    ASSISTANT_RESPONSE(3020, "AI返回JSON推流"),

    ASSISTANT_RESPONSE_END(3021, "AI返回JSON推流结束"),

    CLEAN_CURRENT_MODEL(3030, "清空当前业务模型"),

    CREATE_MODEL(3040, "创建模型"),

    CREATE_FORM(3050, "创建表单信息"),

    EXECUTE_CREATE_TABLE(3060, "执行create table建表语句"),

    CREATE_VIEW(3070, "创建视图");

    @EnumValue
    @JsonValue
    private final Integer code;

    private final String message;

    FluxResponseTypeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static FluxResponseTypeEnum codeToEnum(String code) {
        if (null != code) {
            for (FluxResponseTypeEnum enumItem : FluxResponseTypeEnum.values()) {
                if (enumItem.getCode().toString().equals(code)) {
                    return enumItem;
                }
            }
        }
        return null;
    }

    public static String codeToMessage(String code) {
        if (null != code) {
            for (FluxResponseTypeEnum enumItem : FluxResponseTypeEnum.values()) {
                if (enumItem.getCode().toString().equals(code)) {
                    return enumItem.getMessage();
                }
            }
        }
        return "未知";
    }

    @Override
    public Object getKey() {
        return this.code;
    }

    @Override
    public Object getName() {
        return this.message;
    }

    @Override
    public FluxResponseTypeEnum parseToEnum(String originValue) {
        if (ObjectUtil.isEmpty(originValue)) {
            return null;
        }
        for (FluxResponseTypeEnum value : FluxResponseTypeEnum.values()) {
            if (value.code.toString().equals(originValue)) {
                return value;
            }
        }
        return null;
    }

}