package at.procon.dip.search.service;

import at.procon.dip.search.config.DipSearchProperties;
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 SearchLexicalIndexStartupRunner implements ApplicationRunner {

    private final DipSearchProperties properties;
    private final DocumentLexicalIndexService lexicalIndexService;

    @Override
    public void run(ApplicationArguments args) {
        int updated = lexicalIndexService.backfillMissingVectors(properties.getStartupLexicalBackfillLimit());
        if (updated > 0) {
            log.info("Search lexical index startup backfill updated {} representations", updated);
        }
    }
}
