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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zanxiang.game.module.manage.pojo.dto.GameDTO;
import com.zanxiang.game.module.manage.pojo.vo.GameSupperVO;
import com.zanxiang.game.module.manage.service.IGameService;
import com.zanxiang.game.module.manage.service.IGameSupperService;
import com.zanxiang.game.module.mybatis.entity.GameSupper;
import com.zanxiang.game.module.mybatis.mapper.GameSupperMapper;
import com.zanxiang.module.util.bean.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * @author : lingfeng
 * @time : 2023-09-12
 * @description : 超父游戏
 */
@Slf4j
@Service
public class GameSupperServiceImpl extends ServiceImpl<GameSupperMapper, GameSupper> implements IGameSupperService {

    @Autowired
    private IGameService gameService;

    @Override
    public GameSupper getGameSupperByGameId(Long gameId) {
        GameDTO gameDTO = gameService.getById(gameId);
        if (gameDTO == null) {
            log.error("查询超父游戏, 获取子游戏信息为空! gameId : {}", gameId);
            return null;
        }
        return super.getById(gameDTO.getSuperGameId());
    }

    @Override
    public List<GameSupperVO> getGameSupperList() {
        return super.list().stream()
                .map(gameSupper -> BeanUtil.copy(gameSupper, GameSupperVO.class))
                .collect(Collectors.toList());
    }
}
