package com.YuyeTech.HeartRate.game.gameInfo.service;

import com.YuyeTech.HeartRate.common.service.CommonServiceImpl;
import com.YuyeTech.HeartRate.game.gameInfo.projo.GamePicture;
import com.YuyeTech.HeartRate.game.gameInfo.repository.GamePicturesRepository;
import com.YuyeTech.HeartRate.game.gameInfo.vo.GamePictureVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author:slambb
 * @date:2020/6/24
 */
@Service
@Transactional
public class GamePictureServiceImpl extends CommonServiceImpl<GamePictureVo, GamePicture, Integer> implements GamePictureService {

    @Autowired
    private GamePicturesRepository gamePicturesRepository;
    @Override
    public GamePicture addGamePicture(GamePicture gamePicture) {
        return gamePicturesRepository.save(gamePicture);
    }

    @Override
    public void deleteGamePictureByGpId(Integer gpId) {
        gamePicturesRepository.deleteById(gpId);
    }

    @Override
    @Transactional
    public void deleteAllByTypeAndGameId(Integer type, String gameId) {
        gamePicturesRepository.deleteAllByGpTypeAndGameId(type,gameId);
    }

    @Override
    public Page<GamePicture> findGamePictureByGameId(String gameId, Pageable pageable) {
        return gamePicturesRepository.findByGameId(gameId,pageable);
    }

    @Override
    public List<Integer> findGamePictureIDList(String gameId) {
        return gamePicturesRepository.findPictureIdListByGameId(gameId);
    }

    @Override
    public GamePicture findByGameIdAndType(Integer type, String gameId) {
        return gamePicturesRepository.findByGpTypeAndGameId(type,gameId).orElse(null);
    }
}
