package at.procon.eventhub.tachographfilesession.service;

import org.springframework.stereotype.Component;

@Component
public class VehicleKeyFactory {

    public String createRegistrationKey(String registrationNation, String registrationNumber) {
        String normalizedNation = normalize(registrationNation, "UNKNOWN");
        String normalizedNumber = normalize(registrationNumber, "UNKNOWN");
        return normalizedNation + ":" + normalizedNumber;
    }

    public String createSourceVehicleRegistrationId(String registrationKey) {
        return "VR:" + registrationKey;
    }

    public String createVehicleKey(String vin) {
        return normalize(vin, null);
    }

    public String createSourceVehicleId(String vehicleKey) {
        return vehicleKey == null ? null : "VIN:" + vehicleKey;
    }

    private String normalize(String value, String fallback) {
        if (value == null || value.isBlank()) {
            return fallback;
        }
        return value.trim();
    }
}
