package online.wesal.wesal.repository;

import online.wesal.wesal.entity.Puzzle;
import online.wesal.wesal.entity.PuzzleAttempt;
import online.wesal.wesal.entity.User;
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;
import java.util.Optional;

@Repository
public interface PuzzleAttemptRepository extends JpaRepository<PuzzleAttempt, Long> {
    Optional<PuzzleAttempt> findByUserAndPuzzle(User user, Puzzle puzzle);
    
    @Query("SELECT pa FROM PuzzleAttempt pa WHERE pa.puzzle = :puzzle ORDER BY pa.submittedAt ASC")
    List<PuzzleAttempt> findByPuzzleOrderBySubmittedAtAsc(@Param("puzzle") Puzzle puzzle);
}