package at.procon.eventhub.processing.service;

import at.procon.eventhub.dto.EventHubEventDto;
import at.procon.eventhub.persistence.EventHubEventReadRepository;
import at.procon.eventhub.processing.model.UnifiedVehicleEventsRequest;
import at.procon.eventhub.processing.model.UnifiedEventSourceFamily;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class TachographDbUnifiedVehicleEventSource implements UnifiedVehicleEventSource {

    private static final List<String> SOURCE_KINDS = List.of("DRIVER_CARD", "VEHICLE_UNIT");

    private final EventHubEventReadRepository repository;

    public TachographDbUnifiedVehicleEventSource(EventHubEventReadRepository repository) {
        this.repository = repository;
    }

    @Override
    public boolean supports(UnifiedVehicleEventsRequest request) {
        return request.sourceFamily() == UnifiedEventSourceFamily.TACHOGRAPH_DB;
    }

    @Override
    public List<EventHubEventDto> loadVehicleEvents(UnifiedVehicleEventsRequest request) {
        return repository.findEventsByVehicle(request, "TACHOGRAPH", SOURCE_KINDS);
    }
}
