/**
 * @brief Dummy header for interface_hdf5.pyx.
 *
 * @author Yunhai Li (liyunhai1016@hotmail.com)
 *
 * @copyright Copyright (c) 2025, TBPLaS develop team.
 */
#ifdef WITH_HDF5
#ifndef TBPLAS_PYTHON_INTERFACE_HDF5_H
#define TBPLAS_PYTHON_INTERFACE_HDF5_H

#include <complex>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <memory>

#include "base/io_base.h"
#include "base/io_hdf5.h"

namespace tbplas::python {
using tbplas::base::check_opt_status;
using tbplas::base::HDFFile;
using tbplas::base::OptBinMode;
using tbplas::base::OptStatus;

// Global file handle
std::shared_ptr<HDFFile> DATA_FILE = nullptr;

inline void check_open_state()
{
    if (DATA_FILE == nullptr) {
        std::cerr << "ERROR: HDFFile not opened!" << std::endl;
        std::abort();
    }
}

inline void hdf5_close()
{
    DATA_FILE->close();
    DATA_FILE = nullptr;
}

inline void hdf5_open(const std::string& file_name)
{
    if (DATA_FILE != nullptr) {
        hdf5_close();
    }
    DATA_FILE = std::make_shared<HDFFile>(file_name, OptBinMode::READONLY);
}

inline void hdf5_get_matrix_double_shape(
    const std::string& key,
    uint64_t& num_rows,
    uint64_t& num_cols)
{
    check_open_state();
    DATA_FILE->read_matrix_real_shape(key, num_rows, num_cols);
}

inline void hdf5_get_matrix_complex_shape(
    const std::string& key,
    uint64_t& num_rows,
    uint64_t& num_cols)
{
    check_open_state();
    DATA_FILE->read_matrix_complex_shape(key, num_rows, num_cols);
}

inline void hdf5_get_matrix_double(
    const std::string& key,
    double* data)
{
    check_open_state();
    DATA_FILE->read_matrix_real(key, data);
}

inline void hdf5_get_matrix_complex(
    const std::string& key,
    std::complex<double>* data)
{
    check_open_state();
    DATA_FILE->read_matrix_complex(key, data);
}

} // namespace tbplas::python
#endif // TBPLAS_PYTHON_INTERFACE_HDF5_H
#endif // WITH_HDF5