package de.assecutor.votianlt.pages.domain;

import de.assecutor.votianlt.model.Customer;
import org.bson.types.ObjectId;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import java.util.List;

public interface CustomerRepository extends MongoRepository<Customer, ObjectId> {

    // If you don't need a total row count, Slice is better than Page.
    Slice<Customer> findAllBy(Pageable pageable);

    List<Customer> findByOwner(ObjectId owner);

    // $ne: true matches documents where internal is false, null, or the field is missing
    // (legacy data without the internal field still shows up in customer dropdowns).
    @Query("{ 'owner' : ?0, 'internal' : { $ne: true } }")
    List<Customer> findByOwnerAndInternalFalse(ObjectId owner);
}
