package cn.novalon.gym.manage.sys.handler.stats;

import cn.novalon.gym.manage.sys.core.service.ISysUserService;
import cn.novalon.gym.manage.sys.core.service.ISysRoleService;
import cn.novalon.gym.manage.sys.core.service.IOperationLogService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpStatus;
import org.springframework.mock.web.reactive.function.server.MockServerRequest;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class StatsHandlerTest {

    @Mock
    private ISysUserService userService;

    @Mock
    private ISysRoleService roleService;

    @Mock
    private IOperationLogService operationLogService;

    private StatsHandler statsHandler;

    @BeforeEach
    void setUp() {
        statsHandler = new StatsHandler(userService, roleService, operationLogService);
    }

    @Test
    void testGetOverview() {
        when(userService.count()).thenReturn(Mono.just(100L));
        when(roleService.count()).thenReturn(Mono.just(10L));
        when(operationLogService.count()).thenReturn(Mono.just(1000L));
        when(operationLogService.countToday()).thenReturn(Mono.just(50L));
        
        ServerRequest request = MockServerRequest.builder().build();
        Mono<ServerResponse> response = statsHandler.getOverview(request);
        
        StepVerifier.create(response)
                .expectNextMatches(serverResponse -> 
                    serverResponse.statusCode() == HttpStatus.OK)
                .verifyComplete();
        
        verify(userService).count();
        verify(roleService).count();
        verify(operationLogService).count();
        verify(operationLogService).countToday();
    }
}