package de.assecutor.votianlt.repository;

import de.assecutor.votianlt.model.AppUser;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AppUserRepository extends MongoRepository<AppUser, ObjectId> {

    // Find all AppUsers created by a specific user
    List<AppUser> findByErstelltVon(ObjectId erstelltVon);

    // Find AppUser by email for login
    AppUser findByEmail(String email);

    AppUser findByPasswordCode(String passwordCode);

    // Find AppUser by appCode for task completion notifications
    java.util.Optional<AppUser> findByAppCode(String appCode);

    // Find AppUser by bezeichnung
    AppUser findByBezeichnung(String bezeichnung);

    // Number of app users belonging to a customer (for per-app-user billing);
    // same association as the customer's own app user list (findByErstelltVon)
    long countByErstelltVon(ObjectId erstelltVon);
}
