package com.rj.scheduler;

import com.rj.service.HxrAdminOrderSelectService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.bean.override.mockito.MockitoBean;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

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

@SpringBootTest
@TestPropertySource(
        properties = {
                "spring.task.scheduling.enabled=false",
                "hxr.admin.pull-initial-delay-ms=604800000",
                "app.scheduler.start=true",
                "hxr.admin.enabled=false",
                "app.timezone=Asia/Shanghai"
        })
@Import(LBAdminPullSchedulerTestClockConfiguration.class)
@ActiveProfiles("test")
class LBAdminPullSchedulerWhenHxrDisabledIntegrationTest {

    @Autowired
    private LBAdminPullScheduler lbAdminPullScheduler;

    @Autowired
    private LBAdminPullSchedulerTestClockConfiguration.MutableClock mutableClock;

    @MockitoBean
    private HxrAdminOrderSelectService hxrAdminOrderSelectService;

    @Test
    void pullAdminOrders_eveningWindow_stillSkips() throws Exception {
        mutableClock.setTo(
                ZonedDateTime.of(LocalDate.of(2026, 5, 15), LocalTime.of(20, 0), ZoneId.of("Asia/Shanghai")));

        lbAdminPullScheduler.pullAdminOrders();

        verify(hxrAdminOrderSelectService, never()).fetchAndLogEachOrder();
    }
}
