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

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.google.common.collect.Lists;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * @author: wangli
 * @date: 2022/3/21 15:40
 */
@Getter
public enum MsgStateEnum {

  UNSENT(1, "未发送"),
  HAS_BEEN_SENT(2, "已发送"),
  RECEIVED(3, "已接收"),
  HAVE_READ(4, "已读"),
  COMPLETE(5, "已完成");

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

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

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

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

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

  public static List<MsgStateEnum> successfullyStats() {
    return Lists.newArrayList(
            HAS_BEEN_SENT,
            RECEIVED,
            HAVE_READ,
            COMPLETE
    );
  }

  public static List<MsgStateEnum> unreadStates() {
    return Lists.newArrayList(
            HAS_BEEN_SENT,
            RECEIVED
    );
  }
}