package org.micord.service;

import org.micord.models.*;
import org.micord.utils.ConfigLoader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.FileNotFoundException;
import java.util.*;

@Service
public class ApiService {

	@Autowired
	private ConfigLoader configLoader;

	@Autowired
	private SqlAqlService sqlAndAqlService;

	public void process(String methodName, List<String> ids) throws FileNotFoundException {
		Optional<Requests> optionalConfig = configLoader.loadConfigIfModified(methodName);

		if (optionalConfig.isEmpty()) {
			throw new FileNotFoundException("Configuration for method " + methodName + " could not be loaded.");
		}
		Requests config = optionalConfig.get();
		sqlAndAqlService.processSqlAndAqlRequests(config, ids);
	}
}
