package at.procon.eventhub.reference;

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

import at.procon.eventhub.dto.DriverCardRefDto;
import at.procon.eventhub.dto.VehicleRegistrationRefDto;
import org.junit.jupiter.api.Test;

class TachographNationRegistryTest {

    @Test
    void resolvesKnownNumericNationCodeToAlphaAndNumeric() {
        DriverCardRefDto driverCard = new DriverCardRefDto("13", "CARD-1");
        VehicleRegistrationRefDto registration = new VehicleRegistrationRefDto("13", "W-1");

        assertThat(driverCard.nation()).isEqualTo("D");
        assertThat(driverCard.nationNumericCode()).isEqualTo(13);
        assertThat(driverCard.stableKey()).isEqualTo("13:CARD-1");

        assertThat(registration.nation()).isEqualTo("D");
        assertThat(registration.nationNumericCode()).isEqualTo(13);
        assertThat(registration.stableKey()).isEqualTo("13:W-1");
    }

    @Test
    void resolvesKnownAlphaNationCodeToNumeric() {
        DriverCardRefDto driverCard = new DriverCardRefDto("A", "CARD-1");

        assertThat(driverCard.nation()).isEqualTo("A");
        assertThat(driverCard.nationNumericCode()).isEqualTo(1);
        assertThat(driverCard.stableKey()).isEqualTo("1:CARD-1");
    }

    @Test
    void preservesUnknownNumericNationCodeAsSyntheticLabel() {
        DriverCardRefDto driverCard = new DriverCardRefDto("209", "CARD-1");

        assertThat(driverCard.nation()).isEqualTo("Unknown 209");
        assertThat(driverCard.nationNumericCode()).isEqualTo(209);
        assertThat(driverCard.stableKey()).isEqualTo("209:CARD-1");
    }

    @Test
    void keepsSyntheticTelematicsNationOutsideTachographMapping() {
        VehicleRegistrationRefDto registration = new VehicleRegistrationRefDto("YELLOWFOX", "W-1");

        assertThat(registration.nation()).isEqualTo("YELLOWFOX");
        assertThat(registration.nationNumericCode()).isNull();
        assertThat(registration.stableKey()).isEqualTo("YELLOWFOX:W-1");
    }
}
