package at.procon.eventhub.processing.service;

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

@Component
public class TachographDbUnifiedDriverEventSource implements UnifiedDriverEventSource {

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

    private final EventHubEventReadRepository repository;

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

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

    @Override
    public List<EventHubEventDto> loadDriverEvents(UnifiedDriverEventsRequest request) {
        return repository.findEvents(request, "TACHOGRAPH", SOURCE_KINDS);
    }
}
