package at.procon.dip.migration.audit.startup;

import at.procon.dip.migration.audit.config.LegacyTedAuditProperties;
import at.procon.dip.migration.audit.service.LegacyTedAuditService;
import at.procon.dip.runtime.condition.ConditionalOnRuntimeMode;
import at.procon.dip.runtime.config.RuntimeMode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
@ConditionalOnRuntimeMode(RuntimeMode.NEW)
@RequiredArgsConstructor
@Slf4j
public class LegacyTedAuditStartupRunner implements ApplicationRunner {

    private final LegacyTedAuditProperties properties;
    private final LegacyTedAuditService legacyTedAuditService;

    @Override
    public void run(ApplicationArguments args) {
        if (!properties.isEnabled() || !properties.isStartupRunEnabled()) {
            return;
        }

        int requestedLimit = properties.getStartupRunLimit();
        log.info("Wave 1 / Milestone A startup audit enabled - scanning legacy TED data with limit {}",
                requestedLimit > 0 ? requestedLimit : "unbounded");
        legacyTedAuditService.executeAudit(requestedLimit);
    }
}
