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

import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.login.oauth2.client.remote.role.IRoleRemoteService;
import ink.wgink.login.oauth2.client.service.role.IRoleService;
import ink.wgink.module.oauth2.manager.OAuth2ClientTokenManager;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.dtos.ZTreeDTO;
import ink.wgink.pojo.dtos.role.RoleDTO;
import ink.wgink.pojo.pos.RolePO;
import ink.wgink.pojo.result.SuccessResultData;
import ink.wgink.pojo.result.SuccessResultList;
import ink.wgink.pojo.vos.IdsVO;
import ink.wgink.properties.ApiPathProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: RoleServiceImpl
 * @Description: 角色
 * @Author: wanggeng
 * @Date: 2021/9/22 10:35 下午
 * @Version: 1.0
 */
@Service
public class RoleServiceImpl extends DefaultBaseService implements IRoleService {

    @Autowired
    private IRoleRemoteService roleRemoteService;
    @Autowired
    private ApiPathProperties apiPathProperties;

    @Override
    public RoleDTO get(Map<String, Object> params) {
        return roleRemoteService.get(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(), params);
    }

    @Override
    public RoleDTO get(String roleId) {
        return roleRemoteService.getByRoleId(apiPathProperties.getUserCenter(), roleId, OAuth2ClientTokenManager.getInstance().getToken().getAccessToken());
    }

    @Override
    public List<RoleDTO> list(Map<String, Object> params) {
        return roleRemoteService.list(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(), params);
    }

    @Override
    public List<RoleDTO> listByRoleIds(List<String> roleIds) {
        if(roleIds == null || roleIds.isEmpty()) {
            return new ArrayList<>();
        }
        IdsVO idsVO = new IdsVO();
        idsVO.setIds(roleIds);
        return roleRemoteService.listByRoleIds(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(), idsVO);
    }

    @Override
    public List<RolePO> listPO(Map<String, Object> params) {
        return roleRemoteService.listPO(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(), params);
    }

    @Override
    public List<RolePO> listPO(List<String> roleIds) {
        IdsVO idsVO = new IdsVO();
        idsVO.setIds(roleIds);
        return roleRemoteService.listPOByRoleIds(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(), idsVO);
    }

    @Override
    public List<RoleDTO> listAll(Map<String, Object> params) {
        return roleRemoteService.listAll(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken());
    }

    @Override
    public List<ZTreeDTO> listZTree(Map<String, Object> params) {
        return roleRemoteService.listZTree(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(), params);
    }

    @Override
    public SuccessResultList<List<RoleDTO>> listPage(ListPage page) {
        return roleRemoteService.listPage(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(), page.getPage(), page.getRows(), page.getParams());
    }

    @Override
    public Integer count(Map<String, Object> params) {
        SuccessResultData<Integer> count = roleRemoteService.count(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(), params);
        return count.getData();
    }
}
