package cn.reghao.oss.console.util;

import cn.reghao.oss.console.account.service.UserContext;
import cn.reghao.oss.console.app.model.constant.AppType;
import cn.reghao.oss.console.account.model.constant.RoleType;

import java.util.Set;

/**
 * @author reghao
 * @date 2023-12-01 11:29:21
 */
public class DefaultSetting {
    public static String getDefaultAppEnv() {
        Set<String> roles = UserContext.getUserRoles();
        if (roles.contains(RoleType.ROLE_ADMIN.name())) {
            return EnvType.test.name();
        } else if (roles.contains(RoleType.ROLE_BACKEND.name()) || roles.contains(RoleType.ROLE_FRONTEND.name())) {
            return EnvType.test.name();
        }

        return EnvType.test.name();
    }

    public static String getDefaultAppType() {
        String defaultAppType = AppType.maven.getName();
        Set<String> roles = UserContext.getUserRoles();
        if (roles.contains(RoleType.ROLE_ADMIN.name())) {
            defaultAppType = AppType.dotnetCore.getName();
        } else if (roles.contains(RoleType.ROLE_BACKEND.name())) {
            defaultAppType = AppType.dotnetCore.getName();
        } else if (roles.contains(RoleType.ROLE_FRONTEND.name())) {
            defaultAppType = AppType.npm.getName();
        }

        return defaultAppType;
    }
}
