package cn.axzo.msg.center.api.enums;


import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

import java.util.Arrays;

/**
 * 1 cm_leader; 2 cm_worker; 3 cmp; 9 not_identity
 *
 * @author wangli
 * @date 2022/3/21 21:01
 */
@Getter
public enum ReceiveTypeEnum {
  CM_LEADER(1, "cm_leader"),
  CM_WORKER(2, "cm_worker"),
  CMP_USER(3, "cmp"),
  /**
   * 普通类型消息
   */
  NORMAL(5,"normal"),

  // 主要用于交易侧无身份的情况
  NOT_IDENTITY(9, "not_identity"),
  ;

  @EnumValue
  private final Integer code;
  @JsonValue
  private final String message;

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

  public Integer getCode() {
    return this.code;
  }

  public String getMessage() {
    return this.message;
  }

  public static ReceiveTypeEnum getByMessage(String message) {
    return Arrays.stream(values()).filter(it -> it.message.equals(message)).findFirst()
        .orElse(null);
  }

  public static ReceiveTypeEnum valueOf(Integer code) {
    return Arrays.stream(values()).filter(it -> it.code.equals(code)).findFirst()
        .orElse(null);
  }
}
