package com.njcn.gather.detection.pojo.enums;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;

/**
 * @Author: wr
 * @Date: 2024/12/17 15:37
 */
@Getter
public enum SourceResponseCodeEnum {

    SUCCESS(10200, "请求成功"),
    UNPROCESSED_BUSINESS(10201, "立即响应，业务还未处理，类似肯定应答"),
    NORMAL_RESPONSE(10202, "正常响应中间状态码"),
    ICD_NOT_FOUND(10500, "未找到对应ICD"),
    RECORD_WAVE_FAILED(10501, "录波失败"),
    MESSAGE_PARSING_ERROR(10520, "报文解析有误"),
    CONTROLLED_SOURCE_ERROR(10521, "程控源参数有误"),
    TEST_ITEM_PARSING_ERROR(10522, "测试项解析有误"),
    SOURCE_CONNECTION_ERROR(10523, "源连接失败"),
    SOURCE_CONTROL_ERROR(10524, "获取源控制权失败"),
    RESET_ERROR(10525, "重置源失败"),
    STOP_ERROR(10526, "停止源失败"),
    NOT_INITIALIZED(10527, "源未进行初始化"),
    TARGET_SOURCE_ERROR(10528, "目标源有误（该用户已控制其他源，在关闭前无法操作新的源）"),
    UNABLE_TO_RESPOND(10529, "源状态有误，无法响应报文（例如源处于输出状态，无法响应初始化报文）"),
    UNKNOWN_ERROR(-1, "未知异常"),


    //通讯模块
    DEV_ERROR(10550,"设备连接异常"),
    DEV_TARGET(10551,"设备触发报告异常"),
    RE_OPERATE(10552,"重复的初始化操作"),
    COMMUNICATION_ERR(10553,"通讯模块通讯异常"),
    DATA_RESOLVE(10554,"报文解析异常"),
    NO_INIT_DEV(10556,"不存在上线的设备"),

    //自定义前端展示消息
    SOCKET_ERROR(25000,"服务端连接失败"),
    ALL_SUCCESS(25001,"校验成功"),
    FAIL(25002,"失败"),
    ALL_FAIL(25003,"校验失败"),
    RECEIVE_DATA_TIME_OUT(25004,"接收数据超时"),
    REAL_DATA_CHECK_FAIL(25005,"实时数据不符合"),
    STATISTICS_DATA_CHECK_FAIL(25006,"统计数据不符合"),
    FLICKER_DATA_START(25007,"开始接收闪变数据")





            ;

    private final Integer code;
    private final String message;

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

    public static String getMsgByValue(Integer code) {
        for (SourceResponseCodeEnum state : SourceResponseCodeEnum.values()) {
            if (state.getCode().equals(code)) {
                return state.getMessage();
            }
        }
        return null;
    }

    public static SourceResponseCodeEnum getDictDataEnumByCode(Integer code) {
        for (SourceResponseCodeEnum sourceResponseCodeEnum : SourceResponseCodeEnum.values()) {
            if (ObjectUtil.equals(code, sourceResponseCodeEnum.getCode())) {
                return sourceResponseCodeEnum;
            }
        }
        return null;
    }
}
