package at.procon.eventhub.tachograph.service;

import at.procon.eventhub.config.EventHubProperties;
import at.procon.eventhub.dto.AcquisitionStrategy;
import at.procon.eventhub.dto.ImportMode;
import at.procon.eventhub.dto.ImportScopeDto;
import at.procon.eventhub.importing.AbstractConfiguredImportPlanService;
import at.procon.eventhub.importing.ConfiguredImportPlanDto;
import at.procon.eventhub.tachograph.dto.ConfiguredTachographImportPlanDto;
import at.procon.eventhub.tachograph.dto.TachographImportRequest;
import org.springframework.stereotype.Service;

@Service
public class TachographConfiguredImportPlanService
        extends AbstractConfiguredImportPlanService<TachographImportRequest, ConfiguredTachographImportPlanDto> {

    public TachographConfiguredImportPlanService(EventHubProperties properties) {
        super(() -> properties.getTachograph().getImportPlans(), "tachograph");
    }

    @Override
    protected TachographImportRequest buildRequest(
            EventHubProperties.ConfiguredImportPlan plan,
            ImportMode mode,
            AcquisitionStrategy strategy,
            ImportScopeDto scope
    ) {
        return new TachographImportRequest(
                plan.getTenantKey(),
                plan.getEventSource(),
                plan.getSourceGroup(),
                scope,
                plan.getEventFamilies(),
                mode,
                plan.isRefreshMasterDataFirst(),
                strategy
        );
    }

    @Override
    protected ConfiguredTachographImportPlanDto toDto(EventHubProperties.ConfiguredImportPlan plan) {
        ConfiguredImportPlanDto dto = genericDto(plan);
        return new ConfiguredTachographImportPlanDto(
                dto.planKey(),
                dto.enabled(),
                dto.cron(),
                dto.tenantKey(),
                dto.eventSource(),
                dto.sourceGroup(),
                dto.importScope(),
                dto.eventFamilies(),
                dto.initialMode(),
                dto.scheduledMode(),
                dto.initialStrategy(),
                dto.scheduledStrategy(),
                dto.refreshMasterDataFirst(),
                dto.initialOccurredFrom(),
                dto.initialOccurredTo(),
                dto.runInitialOnStartup()
        );
    }
}
