#pragma once

#include <array>
#include <optional>
#include <span>
#include <vector>

#include <fesa/core/diagnostic.hpp>
#include <fesa/core/vec3.hpp>
#include <fesa/fem/beam_frame.hpp>
#include <fesa/model/beam_section.hpp>
#include <fesa/model/ids.hpp>
#include <fesa/model/material.hpp>

namespace fesa {

struct Beam3D2Input final {
    std::array<Vec3, 2> coordinates;
    std::array<NodeId, 2> node_ids;
    IsotropicElastic material;
    BeamSection section;
};

struct BeamSectionResult final {
    double xi;
    NodeId end_node;
    std::array<double, 6> section_strain;
    std::array<double, 6> section_force;
    double centroid_sigma_xx;
    std::vector<double> sigma_xx;
};

struct Beam3D2Contribution final {
    Matrix12 local_stiffness;
    Matrix12 global_stiffness;
    BeamFrame frame;
};

struct BeamKernelResult final {
    std::optional<Beam3D2Contribution> contribution;
    std::vector<Diagnostic> diagnostics;
};

[[nodiscard]] BeamKernelResult compute_beam3d2(
    const Beam3D2Input& input);

[[nodiscard]] std::vector<BeamSectionResult> recover_beam3d2(
    const Beam3D2Input& input,
    std::span<const double, 12> element_displacement,
    std::span<const std::array<double, 2>> recovery_points);

}  // namespace fesa
