//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Fit/Param/Parameters.h
//! @brief     Defines class Parameters.
//!
//! @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_FIT_PARAM_PARAMETERS_H
#define BORNAGAIN_FIT_PARAM_PARAMETERS_H

#include "Base/Type/Field2D.h"
#include "Fit/Param/Parameter.h"
#include <vector>

namespace mumufit {

//! A collection of fit parameters.

class Parameters {
public:
    using parameters_t = std::vector<Parameter>;
    using const_iterator = parameters_t::const_iterator;
    using iterator = parameters_t::iterator;

    Parameters() = default;

    void add(const Parameter& par);

    const_iterator begin() const { return m_parameters.begin(); }
    const_iterator end() const { return m_parameters.end(); }

    iterator begin() { return m_parameters.begin(); }
    iterator end() { return m_parameters.end(); }

    size_t size() const { return m_parameters.size(); }

    std::vector<double> values() const;
    void setValues(const std::vector<double>& values);

    std::vector<double> errors() const;
    void setErrors(const std::vector<double>& errors);

    const Parameter& operator[](const std::string& name) const;
    const Parameter& operator[](size_t index) const;

    double2d_t correlationMatrix() const { return m_corr_matrix; }
    void setCorrelationMatrix(const double2d_t& matrix);

    size_t freeParameterCount() const;

private:
    bool exists(const std::string& parameter_name) const;
    void check_array_size(const std::vector<double>& values) const;
    size_t check_index(size_t index) const;

    parameters_t m_parameters;
    double2d_t m_corr_matrix; //!< correlation matrix
};

} // namespace mumufit

#endif // BORNAGAIN_FIT_PARAM_PARAMETERS_H
