package at.procon.eventhub.tachographfilesession.service;

import at.procon.eventhub.config.EventHubProperties;
import at.procon.eventhub.processing.driverworkingtime.dto.DriverWorkingTimeProcessingResultDto;
import at.procon.eventhub.processing.driverworkingtime.service.DriverWorkingTimeDerivedProjectionEngine;
import at.procon.eventhub.processing.driverworkingtime.service.DriverWorkingTimeProcessingCore;
import at.procon.eventhub.processing.driverworkingtime.service.DriverWorkingTimeReusableProjectionBuilder;
import at.procon.eventhub.tachographfilesession.dto.TachographEsperDriverProcessingResultDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @deprecated Use {@link DriverWorkingTimeProcessingCore}. This class remains as a
 * compatibility adapter for existing tachograph file-session callers.
 */
@Service
@Deprecated(forRemoval = false)
public class TachographEsperProcessingCore {

    private final DriverWorkingTimeProcessingCore delegate;

    @Autowired
    public TachographEsperProcessingCore(DriverWorkingTimeProcessingCore delegate) {
        this.delegate = delegate;
    }

    public TachographEsperProcessingCore(
            DriverTimelineBuilder driverTimelineBuilder,
            TachographDerivedProjectionCompatibilityFacade compatibilityFacade,
            EventHubProperties properties
    ) {
        this(new DriverWorkingTimeProcessingCore(new DriverWorkingTimeDerivedProjectionEngine(
                compatibilityFacade.commonBuilder()
        )));
    }

    public TachographEsperProcessingCore(
            DriverTimelineBuilder driverTimelineBuilder,
            DriverTimelineReusableProjectionBuilder reusableProjectionBuilder,
            EventHubProperties properties
    ) {
        this(new DriverWorkingTimeProcessingCore(new DriverWorkingTimeDerivedProjectionEngine(
                reusableProjectionBuilder.commonBuilder()
        )));
    }

    public TachographEsperDriverProcessingResultDto process(TachographEsperProcessingInput input) {
        return TachographEsperDriverProcessingResultDto.fromDriverWorkingTime(
                delegate.process(TachographEsperProcessingInputAdapter.toDriverWorkingTimeInput(input))
        );
    }

    public DriverWorkingTimeProcessingResultDto processDriverWorkingTime(TachographEsperProcessingInput input) {
        return delegate.process(TachographEsperProcessingInputAdapter.toDriverWorkingTimeInput(input));
    }
}
