//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      GUI/View/FitControl/FitObjectiveBuilder.h
//! @brief     Defines class FitObjectiveBuilder.
//!
//! @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)
//
//  ************************************************************************************************

#ifndef BORNAGAIN_GUI_VIEW_FITCONTROL_FITOBJECTIVEBUILDER_H
#define BORNAGAIN_GUI_VIEW_FITCONTROL_FITOBJECTIVEBUILDER_H

#include <memory>

class Datafield;
class FitObjective;
class GUIFitObserver;
class IChiSquaredModule;
class IMinimizer;
class ISimulation;
class JobItem;

namespace mumufit {
class Parameters;
}

class FitObjectiveBuilder {
public:
    FitObjectiveBuilder(JobItem* jobItem);
    ~FitObjectiveBuilder();

    void runFit();

    std::unique_ptr<FitObjective> createFitObjective() const;
    std::unique_ptr<IMinimizer> createMinimizer() const;
    std::unique_ptr<IChiSquaredModule> createChiSquaredModule() const;

    mumufit::Parameters createParameters() const;

    void attachObserver(std::shared_ptr<GUIFitObserver> observer);

    void interruptFitting();

private:
    JobItem* m_job_item;

    std::unique_ptr<ISimulation> buildSimulation(const mumufit::Parameters& params) const;

    void update_fit_parameters(const mumufit::Parameters& params) const;

    std::shared_ptr<GUIFitObserver> m_observer;
    std::unique_ptr<FitObjective> m_fit_objective;
};

#endif // BORNAGAIN_GUI_VIEW_FITCONTROL_FITOBJECTIVEBUILDER_H
