package com.jsowell.common.enums.ykc;

import com.jsowell.common.util.BytesUtil;

/**
 * 云快充充电停止原因enum
 *
 * @author JS-ZZA
 * @date 2022/11/4 16:46
 */
public enum YKCChargingStopReasonEnum {
    /**
     * 充电完成
     */
    APP_REMOTE_STOP(0x40, "结束充电，APP远程停止"),
    SOC_FULL(0x41, "结束充电，SOC 达到 100%"),
    CHARGING_ELECTRICITY_ELIGIBLE(0x42, "结束充电，充电电量满足设定条件"),
    CHARGING_AMOUNT_ELIGIBLE(0x43, "结束充电，充电金额满足设定条件"),
    CHARGING_TIME_ELIGIBLE(0x44, "结束充电，充电时间满足设定条件"),
    MANUALLY_STOP_CHARGING(0x45, "结束充电，手动停止充电"),

    OTHER_FORTY_SIX(0x46, "其他方式（预留）"),
    OTHER_FORTY_SEVEN(0x47, "其他方式（预留）"),
    OTHER_FORTY_EIGHT(0x48, "其他方式（预留）"),
    OTHER_FORTY_NINE(0x49, "其他方式（预留）"),

    /**
     * 充电启动失败
     */
    PILE_CONTROL_SYSTEM_FAULT(0x4A, "充电启动失败，充电桩控制系统故障(需要重启或自动恢复)"),
    CONTROL_GUIDANCE_BREAK(0x4B, "充电启动失败，控制导引断开"),
    CIRCUIT_BREAKER_TRIP(0x4C, "充电启动失败，断路器跳位"),
    AMMETER_COMMUNICATION_BREAK(0x4D, "充电启动失败，电表通信中断"),
    LACK_OF_BALANCE(0x4E, "充电启动失败，余额不足"),
    CHARGING_MODEL_FAULT(0x4F, "充电启动失败，充电模块故障"),
    EMERGENCY_STOP_FAULT(0x50, "充电启动失败，急停开入"),
    SPD_ABNORMAL(0x51, "充电启动失败，防雷器异常"),
    BMS_UNREADY(0x52, "充电启动失败， BMS 未就绪"),
    TEMPERATURE_ABNORMAL(0x53, "充电启动失败，温度异常"),
    BATTERY_REVERSE_CONNECT_FAULT(0x54, "充电启动失败，电池反接故障"),
    ELECTRICITY_LOCK_FAULT(0x55, "充电启动失败，电子锁异常"),
    FAIL_CLOSE_ACT(0x56, "充电启动失败，合闸失败"),
    INSULATION_FAULT(0x57, "充电启动失败，绝缘异常"),
    RESERVED_FIFTY_EIGHT(0x58, "预留"),
    RECEIVED_BMS_HANDSHAKE_REPORT_TIMEOUT(0x59, "充电启动失败，接收 BMS 握手报文 BHM 超时"),
    RECEIVED_BMS_AND_CAR_IDENTIFY_REPORT_TIMEOUT(0x5A, "充电启动失败，接收 BMS 和车辆的辨识报文超时 BRM"),
    RECEIVED_BATTERY_CHARGING_DATA_TIMEOUT(0x5B, "充电启动失败，接收电池充电参数报文超时 BCP"),
    RECEIVED_CHARGING_COMPLETE_REPORT_TIMEOUT(0x5C, "充电启动失败，接收 BMS 完成充电准备报文超时 BRO AA"),
    RECEIVED_CHARGING_STATUS_REPORT_TIMEOUT(0x5D, "充电启动失败，接收电池充电总状态报文超时 BCS"),
    RECEIVED_CHARGING_REQUEST_REPORT_TIMEOUT(0x5E, "充电启动失败，接收电池充电要求报文超时 BCL"),
    RECEIVED_BATTERY_STATUS_TIMEOUT(0x5F, "充电启动失败，接收电池状态信息报文超时 BSM"),
    GB_2015_PROHIBIT_CHARGING_AT_BHM(0x60, "充电启动失败， GB2015 电池在 BHM 阶段有电压不允许充电"),
    GB_2015_BATTERY_VOLTAGE_GAP(0x61, "充电启动失败， GB2015 辨识阶段在 BRO_AA 时候电池实际电压 与 BCP 报文电池电压差距大于 5%"),
    B_2015_CHARGER_BRO_AA_TO_BRO_OO(0x62, "充电启动失败， B2015 充电机在预充电阶段从 BRO_AA 变成 BRO_00 状态"),
    RECEIVED_HOST_CONFIG_REPORT_TIMEOUT(0x63, "充电启动失败，接收主机配置报文超时"),
    CHARGER_UNREADY(0x64, "充电启动失败，充电机未准备就绪,我们没有回 CRO AA，对应 老国标"),

    OTHER_SIXTY_FIVE(0x65, "（其他原因）预留"),
    OTHER_SIXTY_SIX(0x66, "（其他原因）预留"),
    OTHER_SIXTY_SEVEN(0x67, "（其他原因）预留"),
    OTHER_SIXTY_EIGHT(0x68, "（其他原因）预留"),
    OTHER_SIXTY_NINE(0x69, "（其他原因）预留"),

    /**
     * 充电异常中止
     */
    SYSTEM_CLOSE_LOCK(0x6A, "充电异常中止，系统闭锁"),
    GUIDANCE_BREAK(0x6B, "充电异常中止，导引断开"),
    BREAKER_TRIP(0x6C, "充电异常中止，断路器跳位"),
    AMMETER_COMMUNICATION_INTERRUPT(0x6D, "充电异常中止，电表通信中断"),
    NOT_SUFFICIENT_FUNDS(0x6E, "充电异常中止，余额不足"),
    AC_PROTECT_ACTION(0x6F, "充电异常中止，交流保护动作"),
    DC_PROTECT_ACTION(0x70, "充电异常中止，直流保护动作"),
    CHARGE_MODEL_UNUSUAL(0x71, "充电异常中止，充电模块故障"),
    FETCH_UP_UNUSUAL(0x72, "充电异常中止，急停开入"),
    SPD_UNUSUAL(0x73, "充电异常中止，防雷器异常"),
    TEMPERATURE_UNUSUAL(0x74, "充电异常中止，温度异常"),
    OUTPUT_UNUSUAL(0x75, "充电异常中止，输出异常"),
    CHARGING_NO_CURRENT(0x76, "充电异常中止，充电无流"),
    ELECTRICITY_LOCK_UNUSUAL(0x77, "充电异常中止，电子锁异常"),

    OTHER_SEVENTY_EIGHT(0x78, "预留"),

    TOTAL_CHARGING_VOLTAGE_UNUSUAL(0x79, "充电异常中止，总充电电压异常"),
    TOTAL_CHARGING_CURRENT_UNUSUAL(0x7A, "充电异常中止，总充电电流异常"),
    SINGLE_CHARGING_VOLTAGE_UNUSUAL(0x7B, "充电异常中止，单体充电电压异常"),
    BATTERY_TEMPERATURE_TOO_HIGH(0x7C, "充电异常中止，电池组过温"),
    HIGHEST_SINGLE_CHARGING_VOLTAGE_UNUSUAL(0x7D, "充电异常中止，最高单体充电电压异常"),
    HIGHEST_BATTERY_TEMPERATURE_TOO_HIGH(0x7E, "充电异常中止，最高电池组过温"),
    BMV_SINGLE_CHARGING_VOLTAGE_UNUSUAL(0x7F, "充电异常中止， BMV 单体充电电压异常"),
    BMT_BATTERY_TEMPERATURE_TOO_HIGH(0x80, "充电异常中止， BMT 电池组过温"),
    BATTERY_STATUS_UNUSUAL_STOP_CHARGING(0x81, "充电异常中止，电池状态异常停止充电"),
    CAR_SEND_REPORT_FORBID_CHARGING(0x82, "充电异常中止，车辆发报文禁止充电"),
    CHARGING_PILE_OUTAGE(0x83, "充电异常中止，充电桩断电"),
    RECEIVED_BATTERY_CHARGING_STATUS_TIMEOUT(0x84, "充电异常中止，接收电池充电总状态报文超时"),
    RECEIVED_BATTERY_CHARGING_REQUEST_TIMEOUT(0x85, "充电异常中止，接收电池充电要求报文超时"),
    RECEIVED_BATTERY_STATUS_DATA_TIMEOUT(0x86, "充电异常中止，接收电池状态信息报文超时"),
    RECEIVED_BMS_STOP_CHARGING_TIMEOUT(0x87, "充电异常中止，接收 BMS 中止充电报文超时"),
    RECEIVED_BMS_CHARGING_STATISTICAL_TIMEOUT(0x88, "充电异常中止，接收 BMS 充电统计报文超时"),
    RECEIVED_CCS_TIMEOUT(0x89, "充电异常中止，接收对侧 CCS 报文超时"),

    OTHER_EIGHTY_A(0x8A, "（其他原因）预留"),
    OTHER_EIGHTY_B(0x8B, "（其他原因）预留"),
    OTHER_EIGHTY_C(0x8C, "（其他原因）预留"),
    OTHER_EIGHTY_D(0x8D, "（其他原因）预留"),
    OTHER_EIGHTY_E(0x8E, "（其他原因）预留"),
    OTHER_EIGHTY_F(0x8F, "（其他原因）预留"),


    /**
     * 未知原因停止
     */
    UNKNOWN_REASON_STOP_CHARGING(0x90, "未知原因停止"),

    ;



    private int code;
    private String msg;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    YKCChargingStopReasonEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 根据code获取停止原因描述
     *
     * @param code 编码
     * @return 停止原因描述
     */
    public static String getMsgByCode(int code) {
        for (YKCChargingStopReasonEnum item : YKCChargingStopReasonEnum.values()) {
            if (item.getCode() == code) {
                return item.getMsg();
            }
        }
        return null;
    }

    public static void main(String[] args) {
        String stopReason = "6B";
        byte[] stopReasonByteArr = new byte[]{0x6B};
        String s = BytesUtil.bin2HexStr(stopReasonByteArr);

        int i = Integer.parseInt(stopReason, 16);
        String stopReasonMsg = YKCChargingStopReasonEnum.getMsgByCode(i);
        System.out.println(stopReasonMsg);
    }
}
