package ru.nbch.indicsearchservice.loader;

import java.nio.file.Path;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import ru.nbch.indicsearchservice.model.enums.DataType;
import ru.nbch.indicsearchservice.model.enums.SearchParameter;
import ru.nbch.indicsearchservice.util.IndicSearchUtils;
import ru.nbch.indicsearchservice.util.MapperHolder;

@Component
public class RuLegalRecordTableLoader implements TableLoader {
    private final MapperHolder mapperHolder;
    private final IndicSearchUtils indicSearchUtils;

    public RuLegalRecordTableLoader(MapperHolder mapperHolder,
                                    IndicSearchUtils indicSearchUtils) {
        this.mapperHolder = mapperHolder;
        this.indicSearchUtils = indicSearchUtils;
    }

    @Override
    public List<DataType> getSuitableDataTypes() {
        return List.of(DataType.GUTDF, DataType.RUTDF);
    }

    @Override
    public List<SearchParameter> getSuitableSearchParameters() {
        return List.of(SearchParameter.FID);
    }

    @Override
    public String getTableName() {
        return "RU_LEGALRECORD";
    }

    @Override
    @Transactional(readOnly = true)
    public Path searchByFid(Set<Integer> fids, UUID taskId) {
        return indicSearchUtils.writeRowsToFile(getTableName(), fids, fidSet -> mapperHolder.getIndicMapper().findAllByFidFromRuLegalRecord(fidSet), taskId);
    }
}
