package ink.wgink.login.oauth2.client.service.menu.impl;

import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.login.oauth2.client.remote.menu.IMenuRemoteService;
import ink.wgink.login.oauth2.client.service.menu.IMenuService;
import ink.wgink.module.oauth2.manager.OAuth2ClientTokenManager;
import ink.wgink.pojo.dtos.menu.MenuDTO;
import ink.wgink.pojo.dtos.role.RoleSimpleDTO;
import ink.wgink.properties.ApiPathProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName: MenuServiceImpl
 * @Description: 菜单业务
 * @Author: wanggeng
 * @Date: 2021/9/22 11:16 上午
 * @Version: 1.0
 */
@Service
public class MenuServiceImpl extends DefaultBaseService implements IMenuService {

    @Autowired
    private IMenuRemoteService menuRemoteService;
    @Autowired
    private ApiPathProperties apiPathProperties;


    @Override
    public List<MenuDTO> listAll(String clientId, String roleId) {
        return menuRemoteService.listAll(apiPathProperties.getUserCenter(), clientId, roleId, OAuth2ClientTokenManager.getInstance().getToken().getAccessToken());
    }

    @Override
    public List<MenuDTO> listAll(String clientId, List<RoleSimpleDTO> roles) {
        StringBuilder roleIdsSB = new StringBuilder();
        for (RoleSimpleDTO role : roles) {
            if (roleIdsSB.length() > 0) {
                roleIdsSB.append("_");
            }
            roleIdsSB.append(role.getRoleId());
        }
        return menuRemoteService.listAll(apiPathProperties.getUserCenter(), clientId, roleIdsSB.toString(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken());
    }
}
