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

import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.login.oauth2.client.remote.position.IPositionRemoteService;
import ink.wgink.login.oauth2.client.service.position.IPositionService;
import ink.wgink.module.oauth2.manager.OAuth2ClientTokenManager;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.dtos.ZTreeDTO;
import ink.wgink.pojo.dtos.position.PositionDTO;
import ink.wgink.pojo.pos.PositionPO;
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.apache.commons.lang3.StringUtils;
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: PositionServiceImpl
 * @Description: 职位
 * @Author: wanggeng
 * @Date: 2021/9/22 10:36 下午
 * @Version: 1.0
 */
@Service
public class PositionServiceImpl extends DefaultBaseService implements IPositionService {

    @Autowired
    private IPositionRemoteService positionRemoteService;
    @Autowired
    private ApiPathProperties apiPathProperties;

    @Override
    public List<PositionDTO> listAllByParentId(String positionParentId) {
        Map<String, Object> params = getHashMap(2);
        params.put("parentId", positionParentId);
        return listAll(params);
    }

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

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

    @Override
    public PositionDTO get(String positionId) {
        return positionRemoteService.getById(apiPathProperties.getUserCenter(), positionId, OAuth2ClientTokenManager.getInstance().getToken().getAccessToken());
    }

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

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

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

    @Override
    public List<PositionDTO> listByPositionIds(List<String> positionIds) {
        if (positionIds == null && positionIds.isEmpty()) {
            return new ArrayList<>();
        }
        IdsVO idsVO = new IdsVO();
        idsVO.setIds(positionIds);
        return positionRemoteService.listByPositionIds(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(), idsVO);
    }

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

    @Override
    public List<PositionPO> listPO(List<String> positionIds) {
        IdsVO idsVO = new IdsVO();
        idsVO.setIds(positionIds);
        return positionRemoteService.listPOByPositionIds(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(), idsVO);
    }

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

    @Override
    public PositionDTO getParentByPositionId(String positionId) {
        if (StringUtils.isBlank(positionId)) {
            return null;
        }
        return positionRemoteService.getParentByPositionId(apiPathProperties.getUserCenter(), positionId, OAuth2ClientTokenManager.getInstance().getToken().getAccessToken());
    }

    @Override
    public List<PositionDTO> listParentByPositionIds(List<String> positionIds) {
        if (positionIds == null && positionIds.isEmpty()) {
            return new ArrayList<>();
        }
        IdsVO idsVO = new IdsVO();
        idsVO.setIds(positionIds);
        return positionRemoteService.listParentByPositionIds(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(), idsVO);
    }

    @Override
    public List<PositionDTO> listByPositionParentIds(List<String> positionParentIds) {
        if (positionParentIds == null && positionParentIds.isEmpty()) {
            return new ArrayList<>();
        }
        IdsVO idsVO = new IdsVO();
        idsVO.setIds(positionParentIds);
        return positionRemoteService.listByPositionParentIds(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(), idsVO);
    }
}
