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

#include "foreign_only_flush.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)
  {
    dzn_runtime.performs_flush (this) = true;
  }
  void port_hello (int i, double d)
  {
    switch (scenario++)
      {
    case 0:
      dzn_locator.get<dzn::pump> ().handle (reinterpret_cast<size_t> (this), 0, [this,i,d]
      {
        this->port_cruel (); this->port_world (i, d); this->dzn_runtime.flush (this);
      });
      break;
    case 1:
      port_cruel ();
      port_world (i, d);
      break;
    case 2:
      dzn_locator.get<dzn::pump> ().handle (reinterpret_cast<size_t> (this), 0, [this]
      {
        this->port_cruel (); this->dzn_runtime.flush (this);
      });
      break;
    case 3:
      port_world (i, d);
      break;
    case 4:
      dzn_locator.get<dzn::pump> ().handle (reinterpret_cast<size_t> (this), 0, [this,i,d]
      {
        this->port_world (i, d); this->dzn_runtime.flush (this);
      });
      break;
    case 5:
      break;
    default:
      assert (!"trace mismatch");
    }
  }
  void port_bye () {}
};
