package de.effigenix.infrastructure.usermanagement.persistence.repository;

import de.effigenix.domain.usermanagement.UserStatus;
import de.effigenix.infrastructure.usermanagement.persistence.entity.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

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

/**
 * Spring Data JPA Repository for UserEntity.
 * Infrastructure Layer - automatically provides CRUD operations.
 *
 * Spring Data generates implementations at runtime based on method names.
 */
@Repository
public interface UserJpaRepository extends JpaRepository<UserEntity, String> {

    /**
     * Finds a user by their username.
     */
    Optional<UserEntity> findByUsername(String username);

    /**
     * Finds a user by their email.
     */
    Optional<UserEntity> findByEmail(String email);

    /**
     * Finds all users assigned to a specific branch.
     */
    List<UserEntity> findByBranchId(String branchId);

    /**
     * Finds all users with a specific status.
     */
    List<UserEntity> findByStatus(UserStatus status);

    /**
     * Checks if a username already exists.
     */
    boolean existsByUsername(String username);

    /**
     * Checks if an email already exists.
     */
    boolean existsByEmail(String email);
}
