//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sample/Multilayer/PlainLayer.h
//! @brief     Defines base class for layers and slices.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2025
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#ifndef BORNAGAIN_SAMPLE_MULTILAYER_PLAINLAYER_H
#define BORNAGAIN_SAMPLE_MULTILAYER_PLAINLAYER_H

#include "Base/Type/Span.h"
#include <memory>
#include <optional>

class Material;
class Roughness;

//! Common base for Layer%s and Slice%s.

class PlainLayer {
public:
    PlainLayer(const Material& material, double thickness, const Roughness* roughness = nullptr);
#ifndef SWIG
    PlainLayer(const Material& material, const Roughness* roughness = nullptr);
    PlainLayer(const Material& material, const Span& span, const Roughness* roughness = nullptr);
    ~PlainLayer();

    PlainLayer(const PlainLayer& other);
    PlainLayer(PlainLayer&& other) noexcept = default;
    PlainLayer& operator=(const PlainLayer&) = delete;
    PlainLayer& operator=(PlainLayer&&) = delete;

    const Material* material() const { return m_material.get(); }

    void setRms(double rms) const { m_rms = rms; }
    double thickness() const { return m_thickness; }
    double rms() const { return m_rms; }
    const Roughness* roughness() const { return m_roughness.get(); }

    void setZSpan(const Span& z_span) const;
    const Span& zSpan() const;
    double low() const;
    double hig() const;

protected:
    std::unique_ptr<const Material> m_material;   //!< Bulk material
    double m_thickness;                           //!< Layer thickness in nanometers
    std::unique_ptr<const Roughness> m_roughness; //!< Roughness of the top surface
    mutable std::optional<Span> m_zspan;          //!< Optional z-span information
    mutable double m_rms{0};                      //!< Computed RMS roughness (cache)
#endif                                            // SWIG
};

#endif // BORNAGAIN_SAMPLE_MULTILAYER_PLAINLAYER_H
