// SPDX-License-Identifier: LicenseRef-Verum-Proprietary
// SPDX-FileCopyrightText: 2023 Verum Software Tools B.V.
// Proprietary and confidential. See LICENSE for terms.

#include "foreign_only.hh"

#include <dzn/pump.hh>
#include <dzn/runtime.hh>

struct foreign: public skel::foreign
{
  int scenario;
  foreign (dzn::locator const& locator)
    : skel::foreign (locator)
    , scenario (0)
  {}
  void port_hello (int i, double d)
  {
    switch (scenario++)
      {
    case 0:
      port_cruel ();
      break;
    case 1:
      dzn_locator.get<dzn::pump> ().handle (reinterpret_cast<size_t> (this), 0, [this]
      {
        this->port_cruel ();
      });
      break;
    case 2:
      port_world (i, d);
      break;
    case 3:
      dzn_locator.get<dzn::pump> ().handle (reinterpret_cast<size_t> (this), 0, [this,i,d]
      {
        this->port_world (i, d);
      });
      break;
    default:
      assert (!"trace mismatch");
    }
  }
  void port_bye () {}
};
