#ifndef QNN_META_HPP
#define QNN_META_HPP

#include <cstdint>
#include <string>
#include <vector>

#include "QnnTypes.h"
#include "qnn_api.hpp"

// Owned copies of tensor/graph metadata extracted from a context binary via
// QnnSystem. The QnnSystemContext_BinaryInfo_t pointers are only valid while
// the system-context handle lives, so everything is copied out.

struct QuantScaleOffset {
    float scale = 0.0f;
    int32_t offset = 0;
};

struct TensorMeta {
    std::string name;
    uint32_t id = 0;
    Qnn_DataType_t data_type = QNN_DATATYPE_UNDEFINED;
    std::vector<uint32_t> dims;
    uint64_t byte_size = 0;

    enum class Quant { None, PerTensor, PerAxis } quant = Quant::None;
    QuantScaleOffset scale_offset; // PerTensor
    int32_t axis = 0;              // PerAxis
    // Stored as the QNN type so execute tensors can point straight at it.
    std::vector<Qnn_ScaleOffset_t> axis_scale_offsets; // PerAxis
};

struct GraphMeta {
    std::string name;
    std::vector<TensorMeta> inputs;
    std::vector<TensorMeta> outputs;
};

// Byte width of a QNN data type (0 for unsupported/opaque types).
uint32_t qnn_data_type_size(Qnn_DataType_t t);

// Parse a serialized context binary's metadata. Returns empty string on
// success, error tag otherwise.
std::string qnn_parse_binary_info(const QnnApi &api,
                                  const void *buf,
                                  uint64_t size,
                                  std::vector<GraphMeta> &out);

#endif // QNN_META_HPP
