package kr.co.accura.wtm.domain.user.repository;

import kr.co.accura.wtm.domain.user.entity.UserRole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserRoleRepository extends JpaRepository<UserRole, Long> {

    List<UserRole> findByUser_Id(Long userId);

    List<UserRole> findByUser_IdAndProjectId(Long userId, Long projectId);

    void deleteByUser_IdAndProjectId(Long userId, Long projectId);

    @Query("SELECT r.code FROM UserRole ur JOIN ur.role r JOIN ur.user u WHERE u.email = :email")
    List<String> findRoleCodesByUserEmail(@Param("email") String email);
}
