package de.effigenix.infrastructure.audit;

import de.effigenix.application.usermanagement.AuditEvent;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.time.OffsetDateTime;
import java.util.List;

/**
 * Spring Data JPA Repository for AuditLogEntity.
 *
 * Read-only operations for querying audit logs.
 * No delete/update operations (HACCP/GoBD compliance - immutable logs).
 */
@Repository
public interface AuditLogJpaRepository extends JpaRepository<AuditLogEntity, String> {

    /**
     * Finds all audit logs for a specific event type.
     */
    List<AuditLogEntity> findByEvent(AuditEvent event);

    /**
     * Finds all audit logs performed by a specific actor.
     */
    List<AuditLogEntity> findByPerformedBy(String performedBy);

    /**
     * Finds all audit logs for a specific entity.
     */
    List<AuditLogEntity> findByEntityId(String entityId);

    /**
     * Finds all audit logs within a time range.
     */
    List<AuditLogEntity> findByTimestampBetween(OffsetDateTime start, OffsetDateTime end);

    /**
     * Finds all audit logs for a specific event and actor.
     */
    List<AuditLogEntity> findByEventAndPerformedBy(AuditEvent event, String performedBy);
}
