package cn.novalon.gym.manage.db.dao;

import cn.novalon.gym.manage.db.entity.AuditLogEntity;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.LocalDateTime;

/**
 * 审计日志数据访问接口
 * 
 * @author 张翔
 * @date 2026-04-08
 */
@Repository
public interface AuditLogDao extends R2dbcRepository<AuditLogEntity, Long> {

    Flux<AuditLogEntity> findByEntityTypeAndDeletedAtIsNull(String entityType);

    Flux<AuditLogEntity> findByEntityIdAndDeletedAtIsNull(Long entityId);

    Flux<AuditLogEntity> findByEntityTypeAndEntityIdAndDeletedAtIsNull(String entityType, Long entityId);

    Flux<AuditLogEntity> findByOperatorAndDeletedAtIsNull(String operator);

    Flux<AuditLogEntity> findByOperationTypeAndDeletedAtIsNull(String operationType);

    Flux<AuditLogEntity> findByOperationTimeBetweenAndDeletedAtIsNull(LocalDateTime startTime, LocalDateTime endTime);

    Flux<AuditLogEntity> findByEntityTypeAndOperationTimeBetweenAndDeletedAtIsNull(
        String entityType, 
        LocalDateTime startTime, 
        LocalDateTime endTime
    );

    Flux<AuditLogEntity> findByOperatorAndOperationTimeBetweenAndDeletedAtIsNull(
        String operator, 
        LocalDateTime startTime, 
        LocalDateTime endTime
    );

    Mono<Long> countByEntityTypeAndDeletedAtIsNull(String entityType);

    Mono<Long> countByOperationTypeAndDeletedAtIsNull(String operationType);

    Mono<Long> countByOperatorAndDeletedAtIsNull(String operator);

    Mono<Long> countByOperationTimeBetweenAndDeletedAtIsNull(LocalDateTime startTime, LocalDateTime endTime);

    Flux<AuditLogEntity> findByDeletedAtIsNull();
}
