
#ifndef PLS_DATAFLOW_INTERNAL_INPUT_H_
#define PLS_DATAFLOW_INTERNAL_INPUT_H_

#include <array>

#include "pls/internal/base/error_handling.h"

#include "token.h"

namespace pls {
namespace dataflow {
namespace internal {

class push_token_cb {
 public:
  virtual void token_pushed(int pos, token_color color) = 0;
};

template<int P, typename T>
class input {
  template<int OP, typename OT>
  friend
  class output;

  std::array<token<T>, P> tokens_;
  bool connected_{false};

  push_token_cb *cb_{nullptr};
  int input_pos_{0};

  void connect() {
    if (connected_) {
      PLS_ERROR("Must only connect on input once. Disconnect the output pointing to it before reconnecting.")
    }
    connected_ = true;
  }

 public:
  void push_token(token<T> token) {
    tokens_[token.color().get_index(P)] = token;
    cb_->token_pushed(input_pos_, token.color());
  }

  void set_cb(push_token_cb *cb, int input_pos) {
    cb_ = cb;
    input_pos_ = input_pos;
  }
};

}
}
}

#endif //PLS_DATAFLOW_INTERNAL_INPUT_H_
