package com.td.boss.game.complayergoods.service;

import com.td.boss.common.service.*;
import com.td.boss.game.complayergoods.pojo.ComPlayerGoods;
import com.td.boss.game.complayergoods.vo.ComPlayerGoodsVo;
import com.td.boss.game.complayergoods.repository.ComPlayerGoodsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

@Service
@Transactional
public class ComPlayerGoodsServiceImpl extends CommonServiceImpl<ComPlayerGoodsVo, ComPlayerGoods, String> implements ComPlayerGoodsService{

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private ComPlayerGoodsRepository comPlayerGoodsRepository;

    @Override
    @Transactional
    public ComPlayerGoods addComPlayerGoods(ComPlayerGoods comPlayerGoods) {
        return comPlayerGoodsRepository.save(comPlayerGoods);
    }

    @Override
    public ComPlayerGoods findById(String goodsId) {
        return comPlayerGoodsRepository.findById(goodsId).orElse(null);
    }

    @Override
    public List<ComPlayerGoods> findAllByPlayerId(Integer playerId) {
        return comPlayerGoodsRepository.findAllByPlayerId(playerId);
    }

    @Override
    public ComPlayerGoods findByPlayerIdAndGoodsIndexAndIsWear(Integer playerId, Integer goodsIndex, Integer isWear) {
        return comPlayerGoodsRepository.findByPlayerIdAndGoodsIndexAndIsWear(playerId,goodsIndex,isWear).orElse(null);
    }
}
