package com.td.Dawa.game.complayers.service;

import com.td.Dawa.common.service.*;
import com.td.Dawa.game.complayers.pojo.ComPlayers;
import com.td.Dawa.game.complayers.vo.ComPlayersVo;
import com.td.Dawa.game.complayers.repository.ComPlayersRepository;
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 ComPlayersServiceImpl extends CommonServiceImpl<ComPlayersVo, ComPlayers, Integer> implements ComPlayersService {

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private ComPlayersRepository comPlayersRepository;

    @Override
    public ComPlayers findByUserId(String userId) {
        return comPlayersRepository.findByUserId(userId).orElse(null);
    }

    @Override
    @Transactional
    public ComPlayers addComPlayers(ComPlayers comPlayers) {
        ComPlayers player = comPlayersRepository.saveAndFlush(comPlayers);
        return player;
    }

    @Override
    public List<String> findUserIds() {
        return comPlayersRepository.findUserIds();
    }
}
