package com.zanxiang.game.module.manage.rpc.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zanxiang.game.module.base.pojo.vo.AgentRpcVO;
import com.zanxiang.game.module.base.rpc.IAgentRpc;
import com.zanxiang.game.module.manage.service.IAgentService;
import com.zanxiang.game.module.mybatis.entity.Agent;
import com.zanxiang.module.util.bean.BeanUtil;
import com.zanxiang.module.util.pojo.ResultVO;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;

@DubboService
public class AgentRpcImpl implements IAgentRpc {
    @Autowired
    private IAgentService agentService;

    @Override
    public ResultVO<List<AgentRpcVO>> getByAgentKeys(List<String> agentKeys) {
        if (CollectionUtils.isEmpty(agentKeys)) {
            return ResultVO.ok();
        }
        return ResultVO.ok(agentService.list(new LambdaQueryWrapper<Agent>()
                .in(Agent::getAgentKey, agentKeys)
        ).stream().map(this::toVOSimple).collect(Collectors.toList()));
    }

    private AgentRpcVO toVOSimple(Agent agent) {
        if (agent == null) {
            return null;
        }
        return BeanUtil.copy(agent, AgentRpcVO.class);
    }
}
