// This file is part of GQCG-GQCP.
//
// Copyright (C) 2017-2020  the GQCG developers
//
// GQCG-GQCP is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GQCG-GQCP is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with GQCG-GQCP.  If not, see <http://www.gnu.org/licenses/>.

#include "DensityMatrix/SpinResolved2DM.hpp"
#include "Utilities/complex.hpp"
#include "gqcpy/include/interfaces.hpp"

#include <pybind11/eigen.h>
#include <pybind11/pybind11.h>


namespace py = pybind11;


namespace gqcpy {


// Provide some shortcuts for frequent namespaces.
namespace py = pybind11;
using namespace GQCP;


/**
 *  Add Python bindings for spin-resolved 2-DMs.
 *
 *  @tparam Class               The type of the Pybind11 `class_` (generated by the compiler).
 *
 *  @param py_class             The Pybind11 `class_` that should obtain APIs related to spin-resolved 2-DMs.
 */
template <typename Class>
void bindSpinResolved2DMInterface(Class& py_class) {

    // The C++ type corresponding to the Python class.
    using Type = typename Class::type;


    py_class

        /*
         *  MARK: General information
         */

        .def(
            "numberOfOrbitals",
            &Type::numberOfOrbitals,
            "Return the number of orbitals (spinors or spin-orbitals, depending on the context) that are related to the sigma-tau part of the spin-resolved 2-DM.")

        .def(
            "orbitalDensity",
            &Type::orbitalDensity,
            "The orbital (total, spin-summed) two-electron density matrix.");


    // Expose the `DoublySpinResolvedBase` API to the Python class.
    bindDoublySpinResolvedBaseInterface(py_class);

    // Expose the `BasisTransformable` API to the Python class.
    bindBasisTransformableInterface(py_class);
}


/**
 *  Register `SpinResolved2DM_d` and `SpinResolved2DM_cd` to the gqcpy module and expose a part of their C++ interface to Python.
 *
 *  @param module           The Pybind11 module in which `SpinResolved2DM_d` and `SpinResolved2DM_cd` should be registered.
 */
void bindSpinResolved2DM(py::module& module) {

    // Define the Python class for `SpinResolved2DM_d` and bind its interface.
    py::class_<SpinResolved2DM<double>> py_SpinResolved2DM_d {module, "SpinResolved2DM_d", "A type that encapsulates the real-valued spin parts of the spin-resolved two-electron density matrix."};
    bindSpinResolved2DMInterface(py_SpinResolved2DM_d);

    // Define the Python class for `SpinResolved2DM_d` and bind its interface.
    py::class_<SpinResolved2DM<complex>> py_SpinResolved2DM_cd {module, "SpinResolved2DM_cd", "A type that encapsulates the complex-valued spin parts of the spin-resolved two-electron density matrix."};
    bindSpinResolved2DMInterface(py_SpinResolved2DM_cd);
}


}  // namespace gqcpy
