package com.crunii.micro.service.sysmgr.api.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

public enum PushTypeEnum {

    MOBILE_PHONE_MESSAGE((byte) 1, "短信推送"),
    STATION_MESSAGE((byte) 2, "站内信");

    Byte type;

    String typeName;

    PushTypeEnum(Byte type, String typeName){
        this.type = type;
        this.typeName = typeName;
    }

    public Byte getType() {
        return type;
    }

    public String getTypeName() {
        return typeName;
    }

    public static String convert(String raw){
        if (StringUtils.isBlank(raw)){
            return null;
        }
        Map<Byte, String> map = Arrays.stream(PushTypeEnum.values()).collect(Collectors.toMap(PushTypeEnum::getType, PushTypeEnum::getTypeName));
        return Arrays.stream(raw.split(",")).map(item -> {
            String s = map.get(Byte.valueOf(item));
            if (StringUtils.isNotBlank(s)){
                return s;
            }
            return null;
        }).filter(StringUtils::isNotBlank).collect(Collectors.joining("、"));
    }
}
