package com.zanxiang.game.module.base.pojo.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * @author : lingfeng
 * @time : 2022-07-13
 * @description : 游戏应用类型
 */
@Getter
@AllArgsConstructor
public enum GameCategoryEnum {

    /**
     * 微信小游戏
     */
    CATEGORY_WX_APPLET(1L, "wx_applet", "微信小游戏"),

    /**
     * 抖音小游戏
     */
    CATEGORY_DY_APPLET(2L, "byte_applet", "抖音小游戏"),

    /**
     * h5游戏
     */
    CATEGORY_H5(3L, "h5", "h5游戏"),

    /**
     * app游戏
     */
    CATEGORY_APP(4L, "app", "app游戏");

    /**
     * 应用id
     */
    private final Long id;

    /**
     * 游戏分类key
     */
    private final String categoryKey;

    /**
     * 描述
     */
    private final String name;

    /**
     * 被分类名字
     *
     * @param category 类别
     * @return {@link String}
     */
    public static String getNameByCategory(Long category) {
        GameCategoryEnum gameCategory = GameCategoryEnum.getGameCategory(category);
        return gameCategory == null ? null : gameCategory.getName();
    }

    /**
     * 获取游戏分类
     *
     * @param category 类别
     * @return {@link String}
     */
    public static GameCategoryEnum getGameCategory(Long category) {
        for (GameCategoryEnum gameCategoryEnum : GameCategoryEnum.values()) {
            if (Objects.equals(gameCategoryEnum.getId(), category)) {
                return gameCategoryEnum;
            }
        }
        return null;
    }
}
