//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sample/Particle/Formfactor.h
//! @brief     Defines interface IDecoratableBorn.
//!
//! @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_SAMPLE_PARTICLE_IFORMFACTOR_H
#define BORNAGAIN_SAMPLE_PARTICLE_IFORMFACTOR_H

#include "Base/Type/Cloneable.h"
#include <heinz/Complex.h>
#include <heinz/Vectors3D.h>
#include <memory>
#include <string>

#ifndef SWIG
#include "Sample/Shape/Shape3D.h"
#endif // SWIG

class Rotation;
class SpinMatrix;
class Spinor;
class WavevectorInfo;

//! Abstract base class for Born form factors.
//!
//! In contrast to the generic IReParticle, a Born form factor does not depend
//! on the incoming and outgoing wave vectors ki and kf, except through their
//! difference, the scattering vector q=ki-kf.

class Formfactor : public Cloneable {
public:
    ~Formfactor() override;

    virtual std::string className() const = 0;
    virtual complex_t formfactorAtBottom(C3 q) const = 0;
    virtual double volume() const;

#ifndef SWIG
    Formfactor* clone() const override = 0;

    //! Returns the (approximate in some cases) radial size of the particle of this
    //! form factor's shape. This is used for SSCA calculations
    virtual double radialExtension() const = 0;

    virtual double zBottom(const Rotation* rotation) const;
    virtual double zTop(const Rotation* rotation) const;

    //! Default implementation only allows rotations along z-axis
    virtual bool canSliceAnalytically(const Rotation* rot) const;

    complex_t theFF(const WavevectorInfo& wavevectors) const;
    SpinMatrix thePolFF(const WavevectorInfo& wavevectors) const;

    virtual void validate() const {}

protected:
    mutable bool m_validated{false};

    //! Shape3D object, used to retrieve vertices (which may be approximate in the case
    //! of round shapes). For soft particles, this will be a hard mean shape.
    mutable std::unique_ptr<Shape3D> m_shape3D;
#endif // SWIG
};

#endif // BORNAGAIN_SAMPLE_PARTICLE_IFORMFACTOR_H
