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

#include "Sample/Multilayer/Cuvette.h"
#include "Sample/Material/Vacuum.h"
#include "Sample/Multilayer/Layer.h"
#include "Sample/Multilayer/LayerStack.h"

Cuvette::Cuvette(double thickness)
{
    Vacuum vacuum;
    Layer top(vacuum);
    Layer middle(vacuum, thickness);
    Layer bottom(vacuum);

    addLayer(top);
    addLayer(middle);
    addLayer(bottom);

    // Store pointer to middle layer for adding particles
    // The layer was cloned by addLayer, so we need to get the actual layer from the stack
    m_middle_layer =
        const_cast<Layer*>(dynamic_cast<const Layer*>(outerStack().sublayers().at(1).get()));
}

Cuvette::Cuvette(LayerStack* outer_stack)
    : Sample(outer_stack)
{
    // Set up the middle layer pointer from the cloned stack
    m_middle_layer =
        const_cast<Layer*>(dynamic_cast<const Layer*>(outerStack().sublayers().at(1).get()));
}

Cuvette* Cuvette::clone() const
{
    // Clone the stack, then create a new Cuvette with the cloned stack
    auto* result = new Cuvette(outerStack().clone());
    result->setExternalField(externalField());
    return result;
}
