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

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @description
 *
 * @author cold_blade
 * @date 2023/9/20
 * @version 1.0
 */
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum TerminalTypeEnum {

    WEB(1, "web"),
    MINI_PROGRAM(2, "mini_program"),
    IOS(3, "ios"),
    ANDROID(4, "android"),
    WEB_VIEW(5, "webview"),
    WECHAT_MINI_PROGRAM(6, "wechat mini-program"),
    /**
     * 所有端
     */
    ALL(-1, "all"),
    ;

    private final Integer code;
    private final String desc;

    public static TerminalTypeEnum descOf(String systemType) {
        if (IOS.desc.equals(systemType)) {
            return IOS;
        }
        if (ANDROID.desc.equals(systemType)) {
            return ANDROID;
        }
        if (WECHAT_MINI_PROGRAM.desc.equals(systemType)) {
            return WECHAT_MINI_PROGRAM;
        }
        if (MINI_PROGRAM.desc.equals(systemType)) {
            return MINI_PROGRAM;
        }
        return WEB;
    }

    public static TerminalTypeEnum codeOf(Integer code) {
        return Arrays.stream(values())
                .filter(e -> e.code.equals(code))
                .findFirst().orElse(null);
    }
}
