#ifndef SRC_SPATIAL_SOLVING_SOLVERFACTORY_HH
#define SRC_SPATIAL_SOLVING_SOLVERFACTORY_HH

#include <dune/common/bitsetvector.hh>
#include <dune/common/parametertree.hh>

#include <dune/solvers/iterationsteps/multigridstep.hh>
#include <dune/solvers/iterationsteps/projectedblockgsstep.hh>
#include <dune/solvers/iterationsteps/blockgsstep.hh>
#include <dune/solvers/norms/energynorm.hh>
#include <dune/solvers/solvers/loopsolver.hh>

//#include <dune/solvers/transferoperators/compressedmultigridtransfer.hh>
//#include <dune/tnnmg/iterationsteps/genericnonlineargs.hh>
//#include <dune/tnnmg/iterationsteps/tnnmgstep.hh>

#include <dune/contact/assemblers/nbodyassembler.hh>

//#include <dune/contact/estimators/hierarchiccontactestimator.hh>
#include <dune/contact/solvers/nsnewtonmgstep.hh>
#include <dune/contact/solvers/nsnewtoncontacttransfer.hh>
#include <dune/contact/solvers/contactobsrestrict.hh>
#include <dune/contact/solvers/contacttransferoperatorassembler.hh>
#include <dune/contact/solvers/nsnewtoncontacttransfer.hh>

#define USE_OLD_TNNMG //needed for old bisection.hh in tnnmg

template <class DeformedGridTEMPLATE, class NonlinearityTEMPLATE, class MatrixType, class VectorType>
class SolverFactory {
//protected:
//  const size_t dim = DeformedGrid::dimension;

public:
  using Matrix = MatrixType;
  using Vector = VectorType;
  using DeformedGrid = DeformedGridTEMPLATE;
  using Nonlinearity = NonlinearityTEMPLATE;

public:
  using Step = Dune::Contact::NonSmoothNewtonMGStep<MatrixType, VectorType>;
  using TransferOperator = Dune::Contact::NonSmoothNewtonContactTransfer<VectorType>;

  SolverFactory(Dune::ParameterTree const &parset, const Dune::Contact::NBodyAssembler<DeformedGrid, VectorType>& nBodyAssembler,
                const Dune::BitSetVector<DeformedGrid::dimension>& ignoreNodes);

  std::shared_ptr<Step> getStep();

  const Dune::Contact::NBodyAssembler<DeformedGrid, VectorType>& getNBodyAssembler() const {
    return nBodyAssembler_;
  }

private:
  const Dune::Contact::NBodyAssembler<DeformedGrid, VectorType>& nBodyAssembler_;

  //ProjectedBlockGSStep<MatrixType, VectorType> baseSolverStep_;
  BlockGSStep<MatrixType, VectorType> baseSolverStep_;
  EnergyNorm<MatrixType, VectorType> baseEnergyNorm_;
  LoopSolver<VectorType> baseSolver_;

  ProjectedBlockGSStep<MatrixType, VectorType> presmoother_;
  ProjectedBlockGSStep<MatrixType, VectorType> postsmoother_;
  std::shared_ptr<Step> multigridStep_;

  std::vector<std::shared_ptr<TransferOperator>> transferOperators_;
};
#endif