//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Base/Math/Integrator.h
//! @brief     Defines classes RealIntegrator, ComplexIntegrator.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#ifdef SWIG
#error no need to expose this header to Swig
#endif // SWIG
#ifndef BORNAGAIN_BASE_MATH_INTEGRATOR_H
#define BORNAGAIN_BASE_MATH_INTEGRATOR_H

#include "Base/Math/IntegratorCollection.h"
#include <heinz/Complex.h>
#include <map>
#include <memory>

namespace Integr {

const std::string AdaptiveGaussKronrod = "AdaptiveGaussKronrod";
const std::string GaussKronrod = "GaussKronrod";
const std::string Romberg = "Romberg";

} // namespace Integr

struct IntegratorOptions {
    std::string type{Integr::AdaptiveGaussKronrod};
    std::map<std::string, double> pars;
};


//! To integrate a real function of a real variable.
class RealIntegrator {
public:
    RealIntegrator(const IntegratorOptions& options = IntegratorOptions());
    double integrate(const std::function<double(double)>& f, double lmin, double lmax);

private:
    IntegratorOptions m_options;
    std::unique_ptr<Integrator> m_integrator;
};


//! To integrate a complex function of a real variable.
class ComplexIntegrator {
public:
    ComplexIntegrator(const IntegratorOptions& options = IntegratorOptions());
    complex_t integrate(const std::function<complex_t(double)>& f, double lmin, double lmax);

private:
    RealIntegrator m_realPart;
    RealIntegrator m_imagPart;
};

#endif // BORNAGAIN_BASE_MATH_INTEGRATOR_H
