//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sample/Multilayer/Slice.h
//! @brief     Defines class Slice.
//!
//! @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)
//
//  ************************************************************************************************

#ifdef SWIG
#error no need to expose this header to Swig
#endif // SWIG
#ifndef BORNAGAIN_SAMPLE_MULTILAYER_SLICE_H
#define BORNAGAIN_SAMPLE_MULTILAYER_SLICE_H

#include "Base/Type/Span.h"
#include "Sample/Multilayer/PlainLayer.h"
#include <heinz/Vectors3D.h>
#include <memory>

class Layer;
class Material;

//! A slice cut from a layer for internal computation.

class Slice : public PlainLayer {
public:
    Slice(size_t number, const Layer& layer, const Span& z_span, const R3& B_field);

    //! Refracting material: averaged bulk material including particle contributions (for Fresnel)
    const Material* refractingMaterial() const { return m_refracting_material.get(); }
    //! Layer material: original bulk material without particle averaging
    const Material* layerMaterial() const { return material(); }
    void setRefractingMaterial(const Material& material);
    R3 bField() const { return m_B_field; }
    void initBField(R3 h_field, double h_z);
    size_t number() const { return m_slice_number; }

private:
    size_t m_slice_number{0};                              //!< Slice number in the refined stack
    std::unique_ptr<const Material> m_refracting_material; //!< Averaged material for Fresnel
    R3 m_B_field;                                          //!< Cached magnetic induction field
};

#endif // BORNAGAIN_SAMPLE_MULTILAYER_SLICE_H
