package at.procon.eventhub.yellowfox.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.yellowfox.dto.ConfiguredYellowFoxD8ImportPlanDto;
import at.procon.eventhub.yellowfox.dto.YellowFoxD8ImportRequest;
import org.springframework.stereotype.Service;

@Service
public class YellowFoxD8ConfiguredImportPlanService
        extends AbstractConfiguredImportPlanService<YellowFoxD8ImportRequest, ConfiguredYellowFoxD8ImportPlanDto> {

    public YellowFoxD8ConfiguredImportPlanService(EventHubProperties properties) {
        super(() -> properties.getYellowFox().getImportPlans(), "yellowfox-d8");
    }

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

    @Override
    protected ConfiguredYellowFoxD8ImportPlanDto toDto(EventHubProperties.ConfiguredImportPlan plan) {
        ConfiguredImportPlanDto dto = genericDto(plan);
        return new ConfiguredYellowFoxD8ImportPlanDto(
                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()
        );
    }
}
