package de.assecutor.votianlt.repository;

import de.assecutor.votianlt.model.TranslationCacheEntry;
import org.bson.types.ObjectId;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository;

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

@Repository
public interface TranslationCacheRepository extends MongoRepository<TranslationCacheEntry, ObjectId> {

    Optional<TranslationCacheEntry> findBySourceText(String sourceText);

    /**
     * Returns the oldest entries (by insertedAt ASC), only projecting the id field,
     * for efficient bulk deletion.
     */
    @Query(value = "{}", fields = "{'_id': 1}")
    List<TranslationCacheEntry> findOldestEntries(Pageable pageable);
}
