package com.lingniu.ingest.identity;

import com.lingniu.ingest.api.ProtocolId;

public record VehicleRegistrationBinding(
        ProtocolId protocol,
        String vin,
        String phone,
        String deviceId,
        String plate,
        Integer province,
        Integer city,
        String maker,
        String deviceType,
        Integer plateColor
) {
    public VehicleRegistrationBinding {
        vin = normalize(vin);
        phone = normalize(phone);
        deviceId = normalize(deviceId);
        plate = normalize(plate);
        maker = normalize(maker);
        deviceType = normalize(deviceType);
        if (phone.isBlank() && deviceId.isBlank() && plate.isBlank()) {
            throw new IllegalArgumentException("at least one registration identifier must not be blank");
        }
    }

    public boolean hasResolvedVin() {
        return !vin.isBlank() && !"unknown".equalsIgnoreCase(vin);
    }

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