package at.procon.eventhub.dto;

/**
 * Source-side grouping information.
 *
 * For tachograph imports this is usually an ORGANISATION from the source DB.
 * For YellowFox this is usually a provider FLEET. The value is acquisition
 * context and can later be mapped to an internal tenant organisation.
 */
public record SourceGroupRefDto(
        SourceGroupType type,
        String sourceEntityId,
        String code,
        String name
) {
    public SourceGroupRefDto {
        sourceEntityId = normalizeNullable(sourceEntityId);
        code = normalizeNullable(code);
        name = normalizeNullable(name);
    }

    public boolean hasValue() {
        return type != null || sourceEntityId != null || code != null || name != null;
    }

    public String stableKey() {
        return (type == null ? "" : type.name()) + "|"
                + (sourceEntityId == null ? "" : sourceEntityId) + "|"
                + (code == null ? "" : code);
    }

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