///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////

#ifndef BINDINGS_PYTHON_CROCODDYL_CORE_ACTIVATION_BASE_HPP_
#define BINDINGS_PYTHON_CROCODDYL_CORE_ACTIVATION_BASE_HPP_

#include "crocoddyl/core/activation-base.hpp"
#include "crocoddyl/core/utils/exception.hpp"
#include "python/crocoddyl/core/core.hpp"

namespace crocoddyl {
namespace python {

class ActivationModelAbstract_wrap
    : public ActivationModelAbstract,
      public bp::wrapper<ActivationModelAbstract> {
 public:
  explicit ActivationModelAbstract_wrap(const std::size_t nr)
      : ActivationModelAbstract(nr), bp::wrapper<ActivationModelAbstract>() {}

  void calc(const boost::shared_ptr<ActivationDataAbstract>& data,
            const Eigen::Ref<const Eigen::VectorXd>& r) {
    if (static_cast<std::size_t>(r.size()) != nr_) {
      throw_pretty("Invalid argument: "
                   << "r has wrong dimension (it should be " +
                          std::to_string(nr_) + ")");
    }
    return bp::call<void>(this->get_override("calc").ptr(), data,
                          (Eigen::VectorXd)r);
  }

  void calcDiff(const boost::shared_ptr<ActivationDataAbstract>& data,
                const Eigen::Ref<const Eigen::VectorXd>& r) {
    if (static_cast<std::size_t>(r.size()) != nr_) {
      throw_pretty("Invalid argument: "
                   << "r has wrong dimension (it should be " +
                          std::to_string(nr_) + ")");
    }
    return bp::call<void>(this->get_override("calcDiff").ptr(), data,
                          (Eigen::VectorXd)r);
  }

  boost::shared_ptr<ActivationDataAbstract> createData() {
    enableMultithreading() = false;
    if (boost::python::override createData = this->get_override("createData")) {
      return bp::call<boost::shared_ptr<ActivationDataAbstract> >(
          createData.ptr());
    }
    return ActivationModelAbstract::createData();
  }

  boost::shared_ptr<ActivationDataAbstract> default_createData() {
    return this->ActivationModelAbstract::createData();
  }
};

}  // namespace python
}  // namespace crocoddyl

#endif  // BINDINGS_PYTHON_CROCODDYL_CORE_ACTIVATION_BASE_HPP_
