package com.mosquito.project.persistence.repository;

import com.mosquito.project.persistence.entity.UserInviteEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface UserInviteRepository extends JpaRepository<UserInviteEntity, Long> {
    List<UserInviteEntity> findByActivityId(Long activityId);
    List<UserInviteEntity> findByActivityIdAndInviterUserId(Long activityId, Long inviterUserId);

    @Query("SELECT u.inviterUserId as userId, COUNT(u) as inviteCount " +
           "FROM UserInviteEntity u " +
           "WHERE u.activityId = :activityId " +
           "GROUP BY u.inviterUserId " +
           "ORDER BY inviteCount DESC")
    List<Object[]> countInvitesByActivityIdGroupByInviter(@Param("activityId") Long activityId);

    @Query("SELECT COUNT(u) FROM UserInviteEntity u WHERE u.activityId = :activityId")
    long countByActivityId(@Param("activityId") Long activityId);
}

