#pragma once

#include "fesa/analysis/analysis_model.hpp"
#include "fesa/analysis/analysis_state.hpp"
#include "fesa/core/status.hpp"
#include "fesa/fem/dof_manager.hpp"
#include "fesa/math/sparse_matrix.hpp"

#include <array>
#include <vector>

namespace fesa {

struct NodeStationResultRow {
    SourceEntityId node;
    EntityIndex representativeElement;
    std::array<double, 4> sectionResultant;
};

// Recovers full-space equilibrium and the active concrete element rows without
// exposing element or sparse-backend details to result consumers.
class ResultRecovery {
public:
    static Status recover(const AnalysisModel& model,
                          const DofManager& dofs,
                          const SparseMatrix& fullStiffness,
                          AnalysisState& state);

    static Result<std::vector<NodeStationResultRow>>
    normalizeSectionResultantsToNodeStations(
        const AnalysisModel& model,
        const std::vector<EndpointResultRow>& endpointRows,
        const std::array<double, 4>& componentTolerances);
};

} // namespace fesa
