package ru.nbch.indicsearchservice.util;

import org.springframework.stereotype.Component;
import ru.nbch.indicsearchservice.repository.MyBatisRepository;
import ru.nbch.indicsearchservice.repository.indic.IndicMapper;

@Component
public class MapperHolder {
    private final DataSourceUpdater dataSourceUpdater;

    public MapperHolder(DataSourceUpdater dataSourceUpdater) {
        this.dataSourceUpdater = dataSourceUpdater;
    }

    public IndicMapper getIndicMapper() {
        MyBatisRepository repository = dataSourceUpdater.getMapper(DataSourceUpdater.DataSourceType.INDIC);
        if (repository instanceof IndicMapper indicMapper) {
            return indicMapper;
        }
        return null;
    }
}
