package at.procon.eventhub.tachographfilesession.service;

import org.springframework.stereotype.Component;

@Component
public class DriverKeyFactory {

    public String createDriverKey(String cardNation, String cardNumber) {
        String normalizedNation = normalize(cardNation, "UNKNOWN");
        String normalizedCardNumber = normalize(cardNumber, "UNKNOWN");
        return normalizedNation + ":" + normalizedCardNumber;
    }

    public String createSourceDriverId(String driverKey) {
        return "DRV:" + driverKey;
    }

    public String createSourceDriverCardId(String driverKey) {
        return "CARD:" + driverKey;
    }

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