package com.pharmacopoeia.repository;

import com.pharmacopoeia.entity.KnowledgePoint;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface KnowledgePointRepository extends JpaRepository<KnowledgePoint, Long> {
    Optional<KnowledgePoint> findByPointId(String pointId);
    List<KnowledgePoint> findBySubject(String subject);
    List<KnowledgePoint> findBySubjectAndChapterId(String subject, String chapterId);

    @Query("SELECT kp.subject, COUNT(kp) FROM KnowledgePoint kp GROUP BY kp.subject ORDER BY COUNT(kp) DESC")
    List<Object[]> countBySubjectGrouped();
}
