//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Device/Beam/Beam.h
//! @brief     Defines class Beam.
//!
//! @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_DEVICE_BEAM_BEAM_H
#define BORNAGAIN_DEVICE_BEAM_BEAM_H

// #include "Base/Types/ICloneable.h"
#include "Param/Node/INode.h"
#include <heinz/Vectors3D.h>

class IFootprint;
class SpinMatrix;

//! An incident neutron or x-ray beam.

class Beam : /*public ICloneable,*/ public INode {
public:
    Beam(double intensity, double wavelength, double alpha, double phi = 0);
    ~Beam() override;

    std::string className() const final { return "Beam"; }

    //... Setters:
    void setFootprint(const IFootprint* shape_factor);
    void setPolarization(R3 polarization);

#ifndef SWIG
    Beam* clone() const /*override*/;

    //... Setters:
    void setIntensity(double intensity);
    void setWavelength(double wavelength);
    void setInclination(double alpha);
    void setAzimuthalAngle(double value);

    std::vector<const INode*> nodeChildren() const override;

    //... Getters
    double intensity() const
    {
        return m_intensity;
    }
    double wavelength() const
    {
        return m_wavelength;
    }
    double wavenumber() const
    {
        return m_wavenumber;
    }
    double alpha_i() const
    {
        return m_alpha;
    }
    double phi_i() const
    {
        return m_phi;
    }
    R3 ki() const;
    R3 k_reflected() const;

    //! Returns polarization density as Bloch vector
    R3 polVector() const;
    //! Returns the polarization density matrix (in spin basis along z-axis)
    SpinMatrix polMatrix() const;

    //! Returns footprint factor.
    const IFootprint* footprint() const;
#endif // SWIG

private:
    Beam(); // needed by Swig
#ifndef SWIG
    Beam(std::vector<double> P);

    void precompute();

    double& m_intensity; //!< beam intensity (neutrons/sec)
    double& m_wavelength;
    double& m_alpha;
    double& m_phi;
    std::shared_ptr<IFootprint> m_shape_factor; //!< footprint correction handler
    R3 m_polarization;                          //!< Bloch vector encoding the beam's polarization

    //... Cached:
    double m_wavenumber;
    R3 m_k;

    friend class DepthprobeSimulationTest;
#endif // SWIG
};

#endif // BORNAGAIN_DEVICE_BEAM_BEAM_H
