// 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 "Basis/NonOrthogonalBasis/GNonOrthogonalStateBasis.hpp"
#include "Basis/NonOrthogonalBasis/RNonOrthogonalStateBasis.hpp"
#include "Basis/NonOrthogonalBasis/UNonOrthogonalStateBasis.hpp"
#include "Mathematical/Algorithm/Algorithm.hpp"
#include "QCMethod/NOCI/NOCI.hpp"
#include "QCMethod/NOCI/NOCIEnvironment.hpp"
#include "Utilities/complex.hpp"

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


namespace gqcpy {


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


/**
 *  Add Python bindings for some APIs related to `QCMethod::NOCI`.
 *
 *  @tparam Class               The type of the Pybind11 `class_` (generated by the compiler).
 *
 *  @param py_class             The Pybind11 `class_` that should obtain APIs related to `QCMethod::NOCI`.
 */
template <typename Class>
void bindQCMethodNOCIInterface(Class& py_class) {

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

    using Scalar = typename Type::Scalar;
    using NonOrthogonalBasis = typename Type::NonOrthogonalBasis;


    py_class

        /*
         *  MARK: Constructors
         */

        .def(py::init<const NonOrthogonalBasis, const size_t>(),
             py::arg("non_orthogonal_state_basis"),
             py::arg("number_of_states") = 1)


        /*
         *  MARK: Optimization
         */

        .def(
            "optimize",
            [](const QCMethod::NOCI<Scalar, NonOrthogonalBasis>& qc_method, Algorithm<GeneralizedEigenproblemEnvironment<Scalar>>& solver, GeneralizedEigenproblemEnvironment<Scalar>& environment) {
                return qc_method.optimize(solver, environment);
            },
            "Optimize the NOCI wave function model: find the NOCI expansion coefficients.");
}


/**
 *  Register multiple templated `QCMethod::NOCI` to the gqcpy module and expose parts of their C++ interfaces to Python.
 *
 *  @param module           The Pybind11 module in which the classes should be registered.
 */
void bindQCMethodNOCI(py::module& module) {

    py::class_<QCMethod::NOCI<double, GNonOrthogonalStateBasis<double>>> py_NOCI_d_GNonOrthogonalStateBasis {module, "NOCI_d_GNonOrthogonalStateBasis", "Real-valued non-orthogonal configuration interaction in a basis that consists of 'generalized' states."};
    bindQCMethodNOCIInterface(py_NOCI_d_GNonOrthogonalStateBasis);

    py::class_<QCMethod::NOCI<double, RNonOrthogonalStateBasis<double>>> py_NOCI_d_RNonOrthogonalStateBasis {module, "NOCI_d_RNonOrthogonalStateBasis", "Real-valued non-orthogonal configuration interaction in a basis that consists of 'restricted' states."};
    bindQCMethodNOCIInterface(py_NOCI_d_RNonOrthogonalStateBasis);

    py::class_<QCMethod::NOCI<double, UNonOrthogonalStateBasis<double>>> py_NOCI_d_UNonOrthogonalStateBasis {module, "NOCI_d_UNonOrthogonalStateBasis", "Real-valued non-orthogonal configuration interaction in a basis that consists of 'unrestricted' states."};
    bindQCMethodNOCIInterface(py_NOCI_d_UNonOrthogonalStateBasis);

    py::class_<QCMethod::NOCI<complex, GNonOrthogonalStateBasis<complex>>> py_NOCI_cd_GNonOrthogonalStateBasis {module, "NOCI_cd_GNonOrthogonalStateBasis", "Complex-valued non-orthogonal configuration interaction in a basis that consists of 'generalized' states."};
    bindQCMethodNOCIInterface(py_NOCI_cd_GNonOrthogonalStateBasis);

    py::class_<QCMethod::NOCI<complex, RNonOrthogonalStateBasis<complex>>> py_NOCI_cd_RNonOrthogonalStateBasis {module, "NOCI_cd_RNonOrthogonalStateBasis", "Complex-valued non-orthogonal configuration interaction in a basis that consists of 'restricted' states."};
    bindQCMethodNOCIInterface(py_NOCI_cd_RNonOrthogonalStateBasis);

    py::class_<QCMethod::NOCI<complex, UNonOrthogonalStateBasis<complex>>> py_NOCI_cd_UNonOrthogonalStateBasis {module, "NOCI_cd_UNonOrthogonalStateBasis", "Complex-valued non-orthogonal configuration interaction in a basis that consists of 'unrestricted' states."};
    bindQCMethodNOCIInterface(py_NOCI_cd_UNonOrthogonalStateBasis);
}


}  // namespace gqcpy
