#pragma once

#include <array>
#include <cstdint>
#include <filesystem>
#include <optional>
#include <vector>

#include <fesa/core/diagnostic.hpp>
#include <fesa/core/vec3.hpp>
#include <fesa/model/beam_section.hpp>
#include <fesa/model/domain.hpp>
#include <fesa/model/entity_origin.hpp>
#include <fesa/model/ids.hpp>
#include <fesa/results/result_database.hpp>

namespace fesa {

struct Hdf5NodeSnapshot final {
    std::uint64_t dense_index;
    NodeId id;
    EntityOrigin origin;
    Vec3 coordinates;
};

struct Hdf5ElementSnapshot final {
    std::uint64_t dense_index;
    ElementId id;
    std::array<std::uint64_t, 2> connectivity;
    SectionId section;
};

struct Hdf5SectionSnapshot final {
    SectionId id;
    double shear_area_y;
    double shear_area_z;
    ShearPropertySource shear_source;
};

struct Hdf5ModelSnapshot final {
    std::vector<Hdf5NodeSnapshot> nodes;
    std::vector<Hdf5ElementSnapshot> elements;
    std::vector<Hdf5SectionSnapshot> sections;
};

struct Hdf5ReadResult final {
    std::optional<ResultDatabase> database;
    std::vector<Diagnostic> diagnostics;
    std::optional<Hdf5ModelSnapshot> model;
};

[[nodiscard]] std::vector<Diagnostic> write_hdf5(
    const std::filesystem::path& path,
    const Domain& domain,
    const ResultDatabase& database);

[[nodiscard]] Hdf5ReadResult read_hdf5_results(
    const std::filesystem::path& path);

}  // namespace fesa
