package at.procon.eventhub.yellowfox.service;

import at.procon.eventhub.config.EventHubProperties;
import at.procon.eventhub.dto.AcquisitionStrategy;
import at.procon.eventhub.dto.EventSourceDto;
import at.procon.eventhub.dto.ImportMode;
import at.procon.eventhub.dto.ImportScopeDto;
import at.procon.eventhub.dto.ImportScopeType;
import at.procon.eventhub.yellowfox.dto.YellowFoxD8ImportRequest;
import java.time.OffsetDateTime;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class YellowFoxD8ConfiguredImportPlanServiceTest {

    @Test
    void scheduledWatermarkRequestKeepsInitialOccurredWindowAsBootstrapScope() {
        EventHubProperties properties = new EventHubProperties();
        EventHubProperties.ConfiguredImportPlan plan = new EventHubProperties.ConfiguredImportPlan();
        plan.setPlanKey("yellowfox-d8-default");
        plan.setTenantKey("Procon");
        plan.setEventSource(new EventSourceDto("YELLOWFOX", "TELEMATICS_PLATFORM", "YELLOWFOX_D8", "logistics-db-prod", "yellowfox-main", null));
        plan.setImportScope(new ImportScopeDto(ImportScopeType.TENANT_ALL, null, false, null, null));
        plan.setScheduledMode(ImportMode.INCREMENTAL_UPDATE);
        plan.setScheduledStrategy(AcquisitionStrategy.SOURCE_ROW_WATERMARK);
        plan.setInitialOccurredFrom(OffsetDateTime.parse("2026-04-01T00:00:00+02:00"));
        plan.setInitialOccurredTo(OffsetDateTime.parse("2026-04-02T00:00:00+02:00"));
        properties.getYellowFox().getImportPlans().add(plan);

        YellowFoxD8ConfiguredImportPlanService service = new YellowFoxD8ConfiguredImportPlanService(properties);
        YellowFoxD8ImportRequest request = service.createScheduledRequest(plan);

        assertThat(request.mode()).isEqualTo(ImportMode.INCREMENTAL_UPDATE);
        assertThat(request.acquisitionStrategy()).isEqualTo(AcquisitionStrategy.SOURCE_ROW_WATERMARK);
        assertThat(request.importScope().occurredFrom()).isEqualTo(OffsetDateTime.parse("2026-04-01T00:00:00+02:00"));
        assertThat(request.importScope().occurredTo()).isEqualTo(OffsetDateTime.parse("2026-04-02T00:00:00+02:00"));
    }
}
