package ru.soune.nocopy.repository;

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 ru.soune.nocopy.entity.violation.ViolationNotion;

import java.util.List;

@Repository
public interface ViolationNotionRepository extends JpaRepository<ViolationNotion, Long> {
    @Query("SELECT vn FROM ViolationNotion vn " +
            "JOIN FETCH vn.user " +
            "WHERE vn.violation.id = :violationId " +
            "ORDER BY vn.createdAt DESC")
    List<ViolationNotion> findByViolationId(@Param("violationId") Long violationId);

    @Query("SELECT COUNT(vn) FROM ViolationNotion vn WHERE vn.violation.id = :violationId")
    long countByViolationId(@Param("violationId") Long violationId);

}
