package cn.pluss.platform.shiro;

import cn.pluss.platform.entitiy.ShiroUser;
import cn.pluss.platform.entity.MenuInfo;
import cn.pluss.platform.entity.RoleInfo;
import cn.pluss.platform.entity.UserApp;
import cn.pluss.platform.entity.UserInfo;
import cn.pluss.platform.mapper.UserAppMapper;
import cn.pluss.platform.menuInfo.MenuInfoService;
import cn.pluss.platform.roleInfo.RoleInfoService;
import cn.pluss.platform.userInfo.UserInfoService;
import cn.pluss.platform.util.StringUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class UserService {

    private final UserInfoService userInfoService;
    private final RoleInfoService roleInfoService;
    private final MenuInfoService menuInfoService;
    private final UserAppMapper userAppMapper;

    /**
     * 查询用户拥有的角色
     */
    public List<RoleInfo> getRoleNames(String loginName) {
        return roleInfoService.getRoleNames(loginName);
    }

    /**
     * 查询用户可进行的操作
     */
    public List<MenuInfo> getPermissionNames(String loginName) {
        return menuInfoService.getPermissionNames(loginName);
    }

    /**
     * 获得当前用户的ShiroUser信息
     */
//    public ShiroUser getShiroUser(String loginName, String password) {
//        UserInfo userInfo = new UserInfo();
//        userInfo.setLoginName(loginName);
//        userInfo.setPassword(password);
//        userInfo = userInfoService.queryUserInfo(userInfo);
//        ShiroUser shiroUser = new ShiroUser();
//        if (userInfo != null) {
//            List<UserApp> queryUserAppList = userAppMapper.selectListByUserId(userInfo.getId());
//            if (queryUserAppList != null && queryUserAppList.size() > 0) {
//                shiroUser.setMerchantCode(queryUserAppList.get(0).getMerchantCode());
//                shiroUser.setUserType(queryUserAppList.get(0).getUserType());
//                if (StringUtil.isNotEmpty(queryUserAppList.get(0).getStaffType())) {
//                    shiroUser.setStaffType(String.valueOf(queryUserAppList.get(0).getStaffType()));
//                }
//            }
//            shiroUser.setLoginName(loginName);
//            shiroUser.setName(userInfo.getTrueName());
//            shiroUser.setStatus(userInfo.getStatus());
//            shiroUser.setId(userInfo.getId());
//            return shiroUser;
//        }
//
//        return null;
//    }

    public int getNotificationMenuId(String link) {
        return userAppMapper.getNotificationMenuId(link);
    }
}
