// 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/SpinResolved1DM.hpp"
#include "Utilities/complex.hpp"
#include "gqcpy/include/interfaces.hpp"

#include <pybind11/pybind11.h>


namespace gqcpy {


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


/**
 *  Add Python bindings for spin-resolved 1-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 1-DMs.
 */
template <typename Class>
void bindSpinResolved1DMInterface(Class& py_class) {

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


    py_class

        /*
         *  MARK: Named constructors
         */

        .def_static(
            "FromOrbital1DM",
            &Type::FromOrbital1DM,
            "Create a spin-resolved 1-DM from an `Orbital1DM`, attributing half of the orbital 1-DM to each of the spin components.")


        /*
         *  MARK: General information
         */

        .def(
            "numberOfOrbitals",
            &Type::numberOfOrbitals,
            py::arg("sigma"),
            "Return the number of orbitals (spinors or spin-orbitals, depending on the context) that correspond to the given spin.")


        /*
         *  MARK: Spin-related operations
         */

        .def(
            "spinDensity",
            &Type::spinDensity,
            "Return the spin-density matrix, i.e. the difference between the alpha and beta 1-DM.")

        .def(
            "orbitalDensity",
            &Type::orbitalDensity,
            "Return the orbital density matrix, i.e. the sum of the alpha and beta 1-DM.");



    // Expose the `SpinResolvedBase` API to the Python class.
    bindSpinResolvedBaseInterface(py_class);

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

    // Expose the `VectorSpaceArithmetic` API to the Python class.
    bindVectorSpaceArithmeticInterface(py_class);
}


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

    // Define the Python class for `SpinResolved1DM_d` and bind its interface.
    py::class_<SpinResolved1DM<double>> py_SpinResolved1DM_d {module, "SpinResolved1DM_d", "A type that encapsulates real-valued alpha and beta (spin-resolved) density matrices."};
    bindSpinResolved1DMInterface(py_SpinResolved1DM_d);

    // Define the Python class for `SpinResolved1DM_cd` and bind its interface.
    py::class_<SpinResolved1DM<complex>> py_SpinResolved1DM_cd {module, "SpinResolved1DM_cd", "A type that encapsulates complex-valued alpha and beta (spin-resolved) density matrices."};
    bindSpinResolved1DMInterface(py_SpinResolved1DM_cd);
}


}  // namespace gqcpy
