package at.procon.eventhub.dto;

/**
 * Tachograph driver-card identifier. The card number is scoped by issuing nation.
 */
public record DriverCardRefDto(
        String nation,
        String number
) {
    public DriverCardRefDto {
        nation = normalize(nation);
        number = normalizeNullable(number);
    }

    public boolean hasValue() {
        return number != null && !number.isBlank();
    }

    public String stableKey() {
        return (nation == null ? "" : nation) + ":" + (number == null ? "" : number);
    }

    private static String normalize(String value) {
        return value == null || value.isBlank() ? null : value.trim().toUpperCase();
    }

    private static String normalizeNullable(String value) {
        return value == null || value.isBlank() ? null : value.trim();
    }
}
