package at.procon.eventhub.processing.model;

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

import java.time.OffsetDateTime;
import java.util.UUID;
import org.junit.jupiter.api.Test;

class UnifiedVehicleEventsRequestTest {

    @Test
    void buildsFileSessionVehicleRequest() {
        UUID sessionId = UUID.randomUUID();

        UnifiedVehicleEventsRequest request = UnifiedVehicleEventsRequest.forTachographFileSession(
                sessionId,
                " VEHICLE:1 ",
                "wdb123",
                "at",
                "W-123AB",
                OffsetDateTime.parse("2026-05-01T00:00:00Z"),
                OffsetDateTime.parse("2026-05-02T00:00:00Z")
        );

        assertThat(request.sourceFamily()).isEqualTo(UnifiedEventSourceFamily.TACHOGRAPH_FILE_SESSION);
        assertThat(request.sessionId()).isEqualTo(sessionId);
        assertThat(request.vehicleSourceEntityId()).isEqualTo("VEHICLE:1");
        assertThat(request.vin()).isEqualTo("WDB123");
        assertThat(request.registrationNation()).isEqualTo("AT");
        assertThat(request.registrationNumber()).isEqualTo("W-123AB");
    }

    @Test
    void buildsDbVehicleRequest() {
        UnifiedVehicleEventsRequest request = UnifiedVehicleEventsRequest.forTachographDb(
                " default ",
                null,
                "vin-42",
                "de",
                "B-123",
                null,
                null
        );

        assertThat(request.sourceFamily()).isEqualTo(UnifiedEventSourceFamily.TACHOGRAPH_DB);
        assertThat(request.tenantKey()).isEqualTo("default");
        assertThat(request.vin()).isEqualTo("VIN-42");
        assertThat(request.registrationNation()).isEqualTo("DE");
        assertThat(request.registrationNumber()).isEqualTo("B-123");
        assertThat(request.hasVehicleSelector()).isTrue();
    }

    @Test
    void rejectsRequestWithoutVehicleSelector() {
        assertThatThrownBy(() -> new UnifiedVehicleEventsRequest(
                UnifiedEventSourceFamily.YELLOWFOX_DB,
                null,
                "default",
                null,
                null,
                null,
                null,
                null,
                null
        )).isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("At least one vehicle selector");
    }
}
