package com.alterdekim.hearthhack.service;

import com.alterdekim.hearthhack.entity.RoomPlayer;
import com.alterdekim.hearthhack.repository.RoomPlayerRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class RoomPlayerService implements IService {

    private final RoomPlayerRepository repository;

    public List<RoomPlayer> getAll() {
        return repository.findAll();
    }

    public List<RoomPlayer> findByRoomId(Long roomId) {
        return repository.findByRoomId(roomId);
    }

    public void joinRoom(Long id, Long userId) {
        repository.save(new RoomPlayer(id, userId));
    }

    public void leaveByUserId(Long userId) {
        repository.deleteAllByUserId(userId);
    }

    public Long hasUserId(Long userId) {
        return repository.hasUserId(userId);
    }

    public void removeByRoomId(Long roomId) {
        repository.removeByRoomId(roomId);
    }
}

