#include <pybind11/pybind11.h>
#include <pybind11/stl.h> // Needed for vectors, maps, sets, strings
#include <pybind11/stl_bind.h> // Needed for binding std::vector, std::map etc if needed directly

#include <string>
#include "const.h"
#include "bindings.h"

namespace py = pybind11;


void register_const_bindings(pybind11::module &const_submodule) {
    py::class_<serif::constant::Constant>(const_submodule, "Constant")
        .def_readonly("name", &serif::constant::Constant::name)
        .def_readonly("value", &serif::constant::Constant::value)
        .def_readonly("uncertainty", &serif::constant::Constant::uncertainty)
        .def_readonly("unit", &serif::constant::Constant::unit)
        .def_readonly("reference", &serif::constant::Constant::reference)
        .def("__repr__", [](const serif::constant::Constant &c) {
            return "<Constant(name='" + c.name + "', value=" + std::to_string(c.value) +
                   ", uncertainty=" + std::to_string(c.uncertainty) +
                   ", unit='" + c.unit + "')>";
        });

    py::class_<serif::constant::Constants>(const_submodule, "Constants")
        .def_property_readonly("loaded", &serif::constant::Constants::isLoaded)
        .def_static("get",
            [](const std::string &name) {
                return py::cast(
                    serif::constant::Constants::getInstance().get(name)
                );
            },
            "Get a constant by name. Returns None if not found."
        )
        .def_static("has",
            [](const std::string &name) {
                return serif::constant::Constants::getInstance().has(name);
            },
            "Check if a constant exists by name.")
        .def_static("keys",
            []() {
                return py::cast(
                    serif::constant::Constants::getInstance().keys()
                );
            },
            "Get a list of all constant names.")
        .def_static("__class_getitem__",
         [](const std::string &name) {
             return py::cast(
                 serif::constant::Constants::getInstance().get(name)
             );
         });

}
