package shop.alien.store.util;

import org.apache.commons.lang3.StringUtils;

/**
 * common_push_task_num.phone_type 与渠道编码映射
 */
public final class CommonPushPhoneType {

    public static final String OPPO = "1";
    public static final String VIVO = "2";
    public static final String HUAWEI = "3";
    public static final String APNS = "4";
    public static final String HONOR = "5";
    public static final String XIAOMI = "6";
    public static final String SAMSUNG = "7";

    private CommonPushPhoneType() {
    }

    public static String fromChannelCode(String channelCode) {
        if (StringUtils.isBlank(channelCode)) {
            return null;
        }
        switch (StringUtils.lowerCase(channelCode.trim())) {
            case "oppo":
                return OPPO;
            case "vivo":
                return VIVO;
            case "huawei":
                return HUAWEI;
            case "apns":
                return APNS;
            case "honor":
                return HONOR;
            case "xiaomi":
                return XIAOMI;
            case "samsung":
                return SAMSUNG;
            default:
                return null;
        }
    }

    public static String channelCodeFromTaskIdKey(String taskIdKey) {
        if (StringUtils.isBlank(taskIdKey) || !taskIdKey.endsWith("_task_id")) {
            return null;
        }
        return taskIdKey.substring(0, taskIdKey.length() - "_task_id".length());
    }
}
