module arch.node.utils;

import prelude open;
import arch.node.types.basics open;
import arch.node.types.identities open;
import arch.node.types.messages open;
import arch.node.types.engine open;
import arch.node.types.anoma as Anoma open;

defaultReplyMsg
  {M C} (cfg : EngineCfg C) (target : EngineID) (replyMsg : M) : EngineMsg M :=
  mkEngineMsg@{
    sender := getEngineIDFromEngineCfg cfg;
    target := target;
    mailbox := some 0;
    msg := replyMsg;
  };

msgActionEffect
  {S B H}
  (env : EngineEnv S B H Anoma.Msg)
  (msgs : List (EngineMsg Anoma.Msg))
  : ActionEffect S B H Anoma.Msg Anoma.Cfg Anoma.Env :=
  mkActionEffect@{
    env := env;
    msgs := msgs;
    timers := [];
    engines := [];
  };

replyActionEffect
  {S B H C}
  (env : EngineEnv S B H Anoma.Msg)
  (cfg : EngineCfg C)
  (target : EngineID)
  (replyMsg : Anoma.Msg)
  : ActionEffect S B H Anoma.Msg Anoma.Cfg Anoma.Env :=
  let
    msg := defaultReplyMsg cfg target replyMsg;
  in msgActionEffect {S} {B} {H} env [msg];

defaultReplyActionEffect
  {S B H C}
  (env : EngineEnv S B H Anoma.Msg)
  (cfg : EngineCfg C)
  (target : EngineID)
  (replyMsg : Anoma.Msg)
  : ActionEffect S B H Anoma.Msg Anoma.Cfg Anoma.Env :=
  replyActionEffect {S} {B} {H} {C} env cfg target replyMsg;