package com.czg.sa;

import cn.dev33.satoken.SaManager;
import cn.dev33.satoken.config.SaTokenConfig;
import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.context.model.SaRequest;
import cn.dev33.satoken.dao.SaTokenDao;
import cn.dev33.satoken.fun.SaFunction;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.session.TokenSign;
import cn.dev33.satoken.stp.SaLoginModel;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpLogic;
import cn.hutool.core.util.StrUtil;
import com.czg.exception.CzgException;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

/**
 * @author Administrator
 */
@Slf4j
@Getter
public class MyStpLogic {
    public static final StpLogic USER_LOGIC = new StpLogic("user");
    public static final StpLogic ADMIN_LOGIC = new StpLogic("admin");

    public Object isPC() {
        return "PC".equals(SaHolder.getRequest().getHeader("Platformtype"));
    }


    public enum LoginType {
        MANAGER, USER, STAFF
    }

    private StpLogic getLogic() {
        boolean hit = SaRouter.match("/user/**").isHit();
        if (hit) {
            return USER_LOGIC;
        }
        return ADMIN_LOGIC;
    }

    /**
     * 校验员工权限
     *
     * @param code 权限码
     */
    public void checkStaffPermission(String code) {
        if (this.isStaff()) {
            StpKit.USER.checkPermission(code);
        }
    }

    /**
     * 身份切换
     *
     * @param id        用户id
     * @param account   账户名
     * @param shopId    店铺id
     * @param shopName  店铺名称
     * @param loginType 登录类型
     * @param isAdmin   是否管理员
     */
    public void switchTo(boolean isMain, Long id, String account, Long shopId, String shopName, LoginType loginType, boolean isAdmin) {
        StpLogic logic = getLogic();
        SaSession session = logic.getSession();
        session.set("shopId", shopId).set("shopName", shopName);
        
//        long headId = logic.getLoginIdAsLong();
//        // 设置主店id
//        Object mainShopId = logic.getSession().get("mainShopId");
//
//        Object parentId1 = session.get("headShopId");
//        logic.getSaTokenDao().set(splicingKeyTokenValue(logic.getTokenValue()), id.toString(), logic.getTokenTimeout());
//        session = logic.getSession();
//        if (session == null) {
//            logic.createLoginSession(id);
//            session = logic.getSession();
//        }
//        // 主店没有headShopId
//        if (!isMain && parentId1 == null) {
//            session.set("headId", headId);
//        }
//
//        session.set("userId", id).set("isAdmin", isAdmin).set("isManager", loginType.equals(LoginType.MANAGER))
//                .set("loginType", loginType).set("account", account).set("shopId", shopId).set("shopName", shopName)
//                .set("isMainShop", isMain)
//                .set("mainShopId", mainShopId);
    }

    /**
     * @param id        登录账号id
     * @param shopName  店铺名称
     * @param shopId    店铺id
     * @param loginType 登录类型枚举
     * @param isAdmin   是否为管理员账号
     */
    public void login(Long id, String account, Long shopId, Long headShopId, String shopName, LoginType loginType, boolean isAdmin, String platForm, boolean isMainShop) {
        StpLogic logic = getLogic();
        logic.login(id);
        if (loginType.equals(LoginType.MANAGER) && shopId == null) {
            throw new CzgException("管理端登录必须传递店铺id");
        }
        SaSession session = logic.getSession().set("userId", id).set("isAdmin", isAdmin).set("isManager", loginType.equals(LoginType.MANAGER))
                .set("platForm", platForm)
                .set("loginType", loginType).set("account", account);
        if (shopId != null) {
            session.set("shopId", shopId);
        }

        if (headShopId != null) {
            if (!isMainShop) {
                session.set("headShopId", headShopId);
            }
            session.set("mainShopId", headShopId);
        }
        if (shopName != null) {
            session.set("shopName", shopName);
        }

        session.set("isMainShop", isMainShop);
    }

    public boolean isMainShop() {
        StpLogic logic = getLogic();
        return (Boolean) logic.getSession().get("isMainShop");
    }

    public Long getMainShopId() {
        StpLogic logic = getLogic();
        return (Long) logic.getSession().get("mainShopId");
    }

    public String getPlatForm() {
        StpLogic logic = getLogic();
        Object platForm = logic.getSession().get("platForm");
        return platForm instanceof String s ? s : "";
    }

    public void reLogin(long id) {
        StpLogic logic = getLogic();
        String token = logic.getTokenValue();
        // 重新绑定新的 userId 到这个 Token
        SaManager.getSaTokenDao().set(SaManager.getConfig().getTokenName() + ":" + token, String.valueOf(id), SaManager.getConfig().getTimeout());
    }


    /**
     * 获取当前登录账号名称 管理端为用户账号 客户端为openId
     *
     * @return 账号或openId
     */
    public String getAccount() {
        StpLogic logic = getLogic();
        return (String) logic.getSession().get("account");
    }

    /**
     * 获取当前店铺用户名，仅后台可用
     *
     * @return 店铺名称
     */
    public String getShopName() {
        StpLogic logic = getLogic();
        Object shopName = logic.getSession().get("shopName");
        return shopName instanceof String s ? s : null;
    }

    /**
     * 获取主店铺id
     *
     * @return id
     */
    public Long getHeadId() {
        Object headId = getLogic().getSession().get("headShopId");
        return headId == null ? null : Long.parseLong(headId.toString());
    }


    /**
     * 获取店铺id
     *
     * @param defaultValue 默认值,传递多个只取第一个
     * @return 返回店铺id，不存在抛出异常，如果传递了默认值不存在返回默认值
     */
    public Long getShopId(Long... defaultValue) {
        StpLogic logic = getLogic();
        Long defaultVal = defaultValue.length > 0 ? defaultValue[0] : null;
        Long shopId;
        int errType;
        if ("admin".equals(logic.getLoginType())) {
            if (logic.getSession() == null) {
                logout();
                throw new CzgException("请重新登录");
            }
            Object info = logic.getSession().get("shopId");
            shopId = info instanceof Long l ? l : null;
            errType = 0;
        } else {
            SaRequest request = SaHolder.getRequest();
            String requestParam = request.getParam("shopId");
            if (StrUtil.isBlank(requestParam)) {
                String header = request.getHeader("shopId");
                shopId = StrUtil.isBlank(header) ? null : Long.parseLong(header);
            } else {
                shopId = Long.parseLong(requestParam);
            }
            errType = 1;
        }
//        Long defaultVal = defaultValue.length > 0 ? defaultValue[0] : null;
//        Object object = logic.getSession().get("isManager");
//        Long shopId;
//        int errType;
//        if (object instanceof Boolean t && t) {
//            Object info = logic.getSession().get("shopId");
//            shopId = info instanceof Long l ? l : null;
//            errType = 0;
//        } else {
//            SaRequest request = SaHolder.getRequest();
//            String requestParam = request.getParam("shopId");
//            if (StrUtil.isBlank(requestParam)) {
//                String header = request.getHeader("shopId");
//                shopId = StrUtil.isBlank(header) ? null : Long.parseLong(header);
//            }else {
//                shopId = Long.parseLong(requestParam);
//            }
//            errType = 1;
//        }

        if (defaultValue.length == 0 && shopId == null) {
            throw new CzgException(errType == 0 ? "shopId获取失败" : "客户端请求头未携带shopId");
        }
        return shopId == null ? defaultVal : shopId;
    }

    /**
     * 获取主店Id 非主店铺则获取当前shopId
     *
     * @return 主店id
     */
    public Long getHeadShopIdBySession() {
        SaSession session = getLogic().getSession();
        Object headId = session.get("headShopId");
        return headId != null ? Long.parseLong(headId.toString()) : session.get("shopId") instanceof Long l ? l : null;
    }

    /**
     * 是否为管理端登录
     *
     * @return 布尔值
     */
    public boolean isManager() {
        StpLogic logic = getLogic();
        Object object = logic.getSession().get("isManager");
        return object instanceof Boolean t && t;
    }


    /**
     * 是否为管理端登录
     *
     * @return 布尔值
     */
    public boolean isStaff() {
        StpLogic logic = getLogic();
        Object loginIdDefaultNull = logic.getLoginIdDefaultNull();
        if (loginIdDefaultNull == null) {
            return false;
        }
        Object object = logic.getSession().get("loginType");
        return object instanceof LoginType t && t.equals(LoginType.STAFF);
    }


    /**
     * 是否为管理员
     *
     * @return 布尔值
     */
    public boolean isAdmin() {
        StpLogic logic = getLogic();
        Object object = logic.getSession().get("isAdmin");
        return object instanceof Boolean t && t;
    }

    /**
     * 添加当前账号的角色
     *
     * @param roleList 角色列表
     * @return 当前实例
     */
    public MyStpLogic addRoleList(List<String> roleList) {
        StpLogic logic = getLogic();
        logic.getSession().set("sa:roleList:" + logic.getLoginType() + ":" + logic.getLoginId(), roleList);
        return this;
    }

    /**
     * 添加当前账号的权限
     *
     * @param permissionList 角色列表
     * @return 当前实例
     */
    public MyStpLogic addPermissionList(List<String> permissionList) {
        StpLogic logic = getLogic();
        logic.getSession().set("sa:permissionList:" + logic.getLoginType() + ":" + logic.getLoginId(), permissionList);
        return this;
    }


    public String getLoginType() {
        return getLogic().getLoginType();
    }


    public StpLogic setLoginType(String loginType) {
        return getLogic().setLoginType(loginType);
    }


    public StpLogic setConfig(SaTokenConfig config) {
        return getLogic().setConfig(config);
    }


    public SaTokenConfig getConfig() {
        return getLogic().getConfig();
    }


    public SaTokenConfig getConfigOrGlobal() {
        return getLogic().getConfigOrGlobal();
    }


    public String getTokenName() {
        return getLogic().getTokenName();
    }


    public String createTokenValue(Object loginId, String device, long timeout, Map<String, Object> extraData) {
        return getLogic().createTokenValue(loginId, device, timeout, extraData);
    }


    public void setTokenValue(String tokenValue) {
        getLogic().setTokenValue(tokenValue);
    }


    public void setTokenValue(String tokenValue, int cookieTimeout) {
        getLogic().setTokenValue(tokenValue, cookieTimeout);
    }


    public void setTokenValue(String tokenValue, SaLoginModel loginModel) {
        getLogic().setTokenValue(tokenValue, loginModel);
    }


    public void setTokenValueToStorage(String tokenValue) {
        getLogic().setTokenValueToStorage(tokenValue);
    }


    public void setTokenValueToCookie(String tokenValue, int cookieTimeout) {
        getLogic().setTokenValueToCookie(tokenValue, cookieTimeout);
    }


    public void setTokenValueToResponseHeader(String tokenValue) {
        getLogic().setTokenValueToResponseHeader(tokenValue);
    }


    public String getTokenValue() {
        return getLogic().getTokenValue();
    }


    public String getTokenValue(boolean noPrefixThrowException) {
        return getLogic().getTokenValue(noPrefixThrowException);
    }


    public String getTokenValueNotCut() {
        return getLogic().getTokenValueNotCut();
    }


    public String getTokenValueNotNull() {
        return getLogic().getTokenValueNotNull();
    }


    public SaTokenInfo getTokenInfo() {
        return getLogic().getTokenInfo();
    }


    public void login(Object id) {
        getLogic().login(id);
    }


    public void login(Object id, String device) {
        getLogic().login(id, device);
    }


    public void login(Object id, boolean isLastingCookie) {
        getLogic().login(id, isLastingCookie);
    }


    public void login(Object id, long timeout) {
        getLogic().login(id, timeout);
    }


    public void login(Object id, SaLoginModel loginModel) {
        getLogic().login(id, loginModel);
    }


    public String createLoginSession(Object id) {
        return getLogic().createLoginSession(id);
    }


    public String createLoginSession(Object id, SaLoginModel loginModel) {
        return getLogic().createLoginSession(id, loginModel);
    }


    public String getOrCreateLoginSession(Object id) {
        return getLogic().getOrCreateLoginSession(id);
    }


    public void logout() {
        getLogic().logout();
    }


    public void logout(Object loginId) {
        getLogic().logout(loginId);
    }


    public void logout(Object loginId, String device) {
        getLogic().logout(loginId, device);
    }


    public void logoutByMaxLoginCount(Object loginId, SaSession session, String device, int maxLoginCount) {
        getLogic().logoutByMaxLoginCount(loginId, session, device, maxLoginCount);
    }


    public void logoutByTokenValue(String tokenValue) {
        getLogic().logoutByTokenValue(tokenValue);
    }


    public void kickout(Object loginId) {
        getLogic().kickout(loginId);
    }


    public void kickout(Object loginId, String device) {
        getLogic().kickout(loginId, device);
    }


    public void kickoutByTokenValue(String tokenValue) {
        getLogic().kickoutByTokenValue(tokenValue);
    }


    public void replaced(Object loginId, String device) {
        getLogic().replaced(loginId, device);
    }


    public boolean isLogin() {
        return getLogic().isLogin();
    }


    public boolean isLogin(Object loginId) {
        return getLogic().isLogin(loginId);
    }


    public void checkLogin() {
        getLogic().checkLogin();
    }


    public Object getLoginId() {
        return getLogic().getLoginId();
    }


    public <T> T getLoginId(T defaultValue) {
        return getLogic().getLoginId(defaultValue);
    }


    public Object getLoginIdDefaultNull() {
        return getLogic().getLoginIdDefaultNull();
    }


    public String getLoginIdAsString() {
        return getLogic().getLoginIdAsString();
    }


    public int getLoginIdAsInt() {
        return getLogic().getLoginIdAsInt();
    }


    public long getLoginIdAsLong() {
        return getLogic().getLoginIdAsLong();
    }


    public Object getLoginIdByToken(String tokenValue) {
        return getLogic().getLoginIdByToken(tokenValue);
    }


    public String getLoginIdNotHandle(String tokenValue) {
        return getLogic().getLoginIdNotHandle(tokenValue);
    }


    public Object getExtra(String key) {
        return getLogic().getExtra(key);
    }


    public Object getExtra(String tokenValue, String key) {
        return getLogic().getExtra(tokenValue, key);
    }


    public boolean isValidLoginId(Object loginId) {
        return getLogic().isValidLoginId(loginId);
    }


    public void saveTokenToIdMapping(String tokenValue, Object loginId, long timeout) {
        getLogic().saveTokenToIdMapping(tokenValue, loginId, timeout);
    }


    public void updateTokenToIdMapping(String tokenValue, Object loginId) {
        getLogic().updateTokenToIdMapping(tokenValue, loginId);
    }


    public void deleteTokenToIdMapping(String tokenValue) {
        getLogic().deleteTokenToIdMapping(tokenValue);
    }


    public SaSession getSessionBySessionId(String sessionId, boolean isCreate, Long timeout, Consumer<SaSession> appendOperation) {
        return getLogic().getSessionBySessionId(sessionId, isCreate, timeout, appendOperation);
    }


    public SaSession getSessionBySessionId(String sessionId) {
        return getLogic().getSessionBySessionId(sessionId);
    }


    public SaSession getSessionByLoginId(Object loginId, boolean isCreate, Long timeout) {
        return getLogic().getSessionByLoginId(loginId, isCreate, timeout);
    }


    public SaSession getSessionByLoginId(Object loginId, boolean isCreate) {
        return getLogic().getSessionByLoginId(loginId, isCreate);
    }


    public SaSession getSessionByLoginId(Object loginId) {
        return getLogic().getSessionByLoginId(loginId);
    }


    public SaSession getSession(boolean isCreate) {
        return getLogic().getSession(isCreate);
    }


    public SaSession getSession() {
        return getLogic().getSession();
    }


    public SaSession getTokenSessionByToken(String tokenValue, boolean isCreate) {
        return getLogic().getTokenSessionByToken(tokenValue, isCreate);
    }


    public SaSession getTokenSessionByToken(String tokenValue) {
        return getLogic().getTokenSessionByToken(tokenValue);
    }


    public SaSession getTokenSession(boolean isCreate) {
        return getLogic().getTokenSession(isCreate);
    }


    public SaSession getTokenSession() {
        return getLogic().getTokenSession();
    }


    public SaSession getAnonTokenSession(boolean isCreate) {
        return getLogic().getAnonTokenSession(isCreate);
    }


    public SaSession getAnonTokenSession() {
        return getLogic().getAnonTokenSession();
    }


    public void deleteTokenSession(String tokenValue) {
        getLogic().deleteTokenSession(tokenValue);
    }


    public void updateLastActiveToNow(String tokenValue) {
        getLogic().updateLastActiveToNow(tokenValue);
    }


    public void updateLastActiveToNow() {
        getLogic().updateLastActiveToNow();
    }


    public void checkActiveTimeout(String tokenValue) {
        getLogic().checkActiveTimeout(tokenValue);
    }


    public void checkActiveTimeout() {
        getLogic().checkActiveTimeout();
    }


    public Long getTokenUseActiveTimeout(String tokenValue) {
        return getLogic().getTokenUseActiveTimeout(tokenValue);
    }


    public long getTokenUseActiveTimeoutOrGlobalConfig(String tokenValue) {
        return getLogic().getTokenUseActiveTimeoutOrGlobalConfig(tokenValue);
    }


    public long getTokenLastActiveTime(String tokenValue) {
        return getLogic().getTokenLastActiveTime(tokenValue);
    }


    public long getTokenLastActiveTime() {
        return getLogic().getTokenLastActiveTime();
    }


    public long getTokenTimeout() {
        return getLogic().getTokenTimeout();
    }


    public long getTokenTimeout(String token) {
        return getLogic().getTokenTimeout(token);
    }


    public long getTokenTimeoutByLoginId(Object loginId) {
        return getLogic().getTokenTimeoutByLoginId(loginId);
    }


    public long getSessionTimeout() {
        return getLogic().getSessionTimeout();
    }


    public long getSessionTimeoutByLoginId(Object loginId) {
        return getLogic().getSessionTimeoutByLoginId(loginId);
    }


    public long getTokenSessionTimeout() {
        return getLogic().getTokenSessionTimeout();
    }


    public long getTokenSessionTimeoutByTokenValue(String tokenValue) {
        return getLogic().getTokenSessionTimeoutByTokenValue(tokenValue);
    }


    public long getTokenActiveTimeout() {
        return getLogic().getTokenActiveTimeout();
    }


    public long getTokenActiveTimeoutByToken(String tokenValue) {
        return getLogic().getTokenActiveTimeoutByToken(tokenValue);
    }


    public void renewTimeout(long timeout) {
        getLogic().renewTimeout(timeout);
    }


    public void renewTimeout(String tokenValue, long timeout) {
        getLogic().renewTimeout(tokenValue, timeout);
    }


    public List<String> getRoleList() {
        return getLogic().getRoleList();
    }


    public List<String> getRoleList(Object loginId) {
        return getLogic().getRoleList(loginId);
    }


    public boolean hasRole(String role) {
        return getLogic().hasRole(role);
    }


    public boolean hasRole(Object loginId, String role) {
        return getLogic().hasRole(loginId, role);
    }


    public boolean hasRoleAnd(String... roleArray) {
        return getLogic().hasRoleAnd(roleArray);
    }


    public boolean hasRoleOr(String... roleArray) {
        return getLogic().hasRoleOr(roleArray);
    }


    public void checkRole(String role) {
        getLogic().checkRole(role);
    }


    public void checkRoleAnd(String... roleArray) {
        getLogic().checkRoleAnd(roleArray);
    }


    public void checkRoleOr(String... roleArray) {
        getLogic().checkRoleOr(roleArray);
    }


    public List<String> getPermissionList() {
        return getLogic().getPermissionList();
    }


    public List<String> getPermissionList(Object loginId) {
        return getLogic().getPermissionList(loginId);
    }


    public boolean hasPermission(String permission) {
        return getLogic().hasPermission(permission);
    }


    public boolean hasPermission(Object loginId, String permission) {
        return getLogic().hasPermission(loginId, permission);
    }


    public boolean hasPermissionAnd(String... permissionArray) {
        return getLogic().hasPermissionAnd(permissionArray);
    }


    public boolean hasPermissionOr(String... permissionArray) {
        return getLogic().hasPermissionOr(permissionArray);
    }


    public void checkPermission(String permission) {
        getLogic().checkPermission(permission);
    }


    public void checkPermissionAnd(String... permissionArray) {
        getLogic().checkPermissionAnd(permissionArray);
    }


    public void checkPermissionOr(String... permissionArray) {
        getLogic().checkPermissionOr(permissionArray);
    }


    public String getTokenValueByLoginId(Object loginId) {
        return getLogic().getTokenValueByLoginId(loginId);
    }


    public String getTokenValueByLoginId(Object loginId, String device) {
        return getLogic().getTokenValueByLoginId(loginId, device);
    }


    public List<String> getTokenValueListByLoginId(Object loginId) {
        return getLogic().getTokenValueListByLoginId(loginId);
    }


    public List<String> getTokenValueListByLoginId(Object loginId, String device) {
        return getLogic().getTokenValueListByLoginId(loginId, device);
    }


    public List<TokenSign> getTokenSignListByLoginId(Object loginId, String device) {
        return getLogic().getTokenSignListByLoginId(loginId, device);
    }


    public String getLoginDevice() {
        return getLogic().getLoginDevice();
    }


    public String getLoginDeviceByToken(String tokenValue) {
        return getLogic().getLoginDeviceByToken(tokenValue);
    }


    public List<String> searchTokenValue(String keyword, int start, int size, boolean sortType) {
        return getLogic().searchTokenValue(keyword, start, size, sortType);
    }


    public List<String> searchSessionId(String keyword, int start, int size, boolean sortType) {
        return getLogic().searchSessionId(keyword, start, size, sortType);
    }


    public List<String> searchTokenSessionId(String keyword, int start, int size, boolean sortType) {
        return getLogic().searchTokenSessionId(keyword, start, size, sortType);
    }


    public void disable(Object loginId, long time) {
        getLogic().disable(loginId, time);
    }


    public boolean isDisable(Object loginId) {
        return getLogic().isDisable(loginId);
    }


    public void checkDisable(Object loginId) {
        getLogic().checkDisable(loginId);
    }


    public long getDisableTime(Object loginId) {
        return getLogic().getDisableTime(loginId);
    }


    public void untieDisable(Object loginId) {
        getLogic().untieDisable(loginId);
    }


    public void disable(Object loginId, String service, long time) {
        getLogic().disable(loginId, service, time);
    }


    public boolean isDisable(Object loginId, String service) {
        return getLogic().isDisable(loginId, service);
    }


    public void checkDisable(Object loginId, String... services) {
        getLogic().checkDisable(loginId, services);
    }


    public long getDisableTime(Object loginId, String service) {
        return getLogic().getDisableTime(loginId, service);
    }


    public void untieDisable(Object loginId, String... services) {
        getLogic().untieDisable(loginId, services);
    }


    public void disableLevel(Object loginId, int level, long time) {
        getLogic().disableLevel(loginId, level, time);
    }


    public void disableLevel(Object loginId, String service, int level, long time) {
        getLogic().disableLevel(loginId, service, level, time);
    }


    public boolean isDisableLevel(Object loginId, int level) {
        return getLogic().isDisableLevel(loginId, level);
    }


    public boolean isDisableLevel(Object loginId, String service, int level) {
        return getLogic().isDisableLevel(loginId, service, level);
    }


    public void checkDisableLevel(Object loginId, int level) {
        getLogic().checkDisableLevel(loginId, level);
    }


    public void checkDisableLevel(Object loginId, String service, int level) {
        getLogic().checkDisableLevel(loginId, service, level);
    }


    public int getDisableLevel(Object loginId) {
        return getLogic().getDisableLevel(loginId);
    }


    public int getDisableLevel(Object loginId, String service) {
        return getLogic().getDisableLevel(loginId, service);
    }


    public void endSwitch() {
        getLogic().endSwitch();
    }


    public boolean isSwitch() {
        return getLogic().isSwitch();
    }


    public Object getSwitchLoginId() {
        return getLogic().getSwitchLoginId();
    }


    public void switchTo(Object loginId, SaFunction function) {
        getLogic().switchTo(loginId, function);
    }


    public void openSafe(long safeTime) {
        getLogic().openSafe(safeTime);
    }


    public void openSafe(String service, long safeTime) {
        getLogic().openSafe(service, safeTime);
    }


    public boolean isSafe() {
        return getLogic().isSafe();
    }


    public boolean isSafe(String service) {
        return getLogic().isSafe(service);
    }


    public boolean isSafe(String tokenValue, String service) {
        return getLogic().isSafe(tokenValue, service);
    }


    public void checkSafe() {
        getLogic().checkSafe();
    }


    public void checkSafe(String service) {
        getLogic().checkSafe(service);
    }


    public long getSafeTime() {
        return getLogic().getSafeTime();
    }


    public long getSafeTime(String service) {
        return getLogic().getSafeTime(service);
    }


    public void closeSafe() {
        getLogic().closeSafe();
    }


    public void closeSafe(String service) {
        getLogic().closeSafe(service);
    }


    public String splicingKeyTokenName() {
        return getLogic().splicingKeyTokenName();
    }


    public String splicingKeyTokenValue(String tokenValue) {
        return getLogic().splicingKeyTokenValue(tokenValue);
    }


    public String splicingKeySession(Object loginId) {
        return getLogic().splicingKeySession(loginId);
    }


    public String splicingKeyTokenSession(String tokenValue) {
        return getLogic().splicingKeyTokenSession(tokenValue);
    }


    public String splicingKeyLastActiveTime(String tokenValue) {
        return getLogic().splicingKeyLastActiveTime(tokenValue);
    }


    public String splicingKeySwitch() {
        return getLogic().splicingKeySwitch();
    }


    public String splicingKeyJustCreatedSave() {
        return getLogic().splicingKeyJustCreatedSave();
    }


    public String splicingKeyDisable(Object loginId, String service) {
        return getLogic().splicingKeyDisable(loginId, service);
    }


    public String splicingKeySafe(String tokenValue, String service) {
        return getLogic().splicingKeySafe(tokenValue, service);
    }


    public SaTokenDao getSaTokenDao() {
        return getLogic().getSaTokenDao();
    }


    public boolean getConfigOfIsShare() {
        return getLogic().getConfigOfIsShare();
    }


    public boolean isOpenCheckActiveTimeout() {
        return getLogic().isOpenCheckActiveTimeout();
    }


    public int getConfigOfCookieTimeout() {
        return getLogic().getConfigOfCookieTimeout();
    }


    public int getConfigOfMaxTryTimes() {
        return getLogic().getConfigOfMaxTryTimes();
    }


    public boolean hasElement(List<String> list, String element) {
        return getLogic().hasElement(list, element);
    }


    public boolean isSupportExtra() {
        return getLogic().isSupportExtra();
    }
}
