package de.nilzbu.mytimetracker.repository;

import de.nilzbu.mytimetracker.model.TimeEntry;
import de.nilzbu.mytimetracker.model.User;
import org.springframework.data.jpa.repository.JpaRepository;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

public interface TimeEntryRepository extends JpaRepository<TimeEntry, Long> {

    List<TimeEntry> findAllByUserOrderByDateDesc(User user);

    Optional<TimeEntry> findTopByUserOrderByDateDesc(User user);

    boolean existsByUserAndDate(User user, LocalDate date);

    Optional<TimeEntry> findByUserAndDate(User user, LocalDate date);

    List<TimeEntry> findByUserAndDateBetween(User user, LocalDate start, LocalDate end);

    Optional<TimeEntry> findFirstByUserOrderByDateAsc(User user);

}