/**
 * Auto-generated execution implementation for simple_mod ChiMod
 * Implements Container virtual APIs (Run, Del, SaveTask, LoadTask, NewCopy, Aggregate)
 * using switch-case dispatch
 * 
 * This file is autogenerated - do not edit manually.
 * Changes should be made to the autogen tool or the YAML configuration.
 */

#include "external_test/simple_mod/simple_mod_runtime.h"
#include "external_test/simple_mod/autogen/simple_mod_methods.h"
#include <chimaera/chimaera.h>

namespace external_test::simple_mod {

//==============================================================================
// Container Virtual API Implementations
//==============================================================================

void Runtime::Init(const chi::PoolId &pool_id, const std::string &pool_name) {
  // Call base class initialization
  chi::Container::Init(pool_id, pool_name);

  // Initialize the client for this ChiMod
  client_ = Client(pool_id);
}

void Runtime::Run(chi::u32 method, hipc::FullPtr<chi::Task> task_ptr, chi::RunContext& rctx) {
  switch (method) {
    default: {
      // Unknown method - do nothing
      break;
    }
  }
}

void Runtime::Del(chi::u32 method, hipc::FullPtr<chi::Task> task_ptr) {
  // Use IPC manager to deallocate task from shared memory
  auto* ipc_manager = CHI_IPC;
  
  switch (method) {
    default: {
      // For unknown methods, still try to delete from main segment
      ipc_manager->DelTask(task_ptr);
      break;
    }
  }
}

void Runtime::SaveTask(chi::u32 method, chi::SaveTaskArchive& archive, 
                        hipc::FullPtr<chi::Task> task_ptr) {
  switch (method) {
    default: {
      // Unknown method - do nothing
      break;
    }
  }
}

void Runtime::LoadTask(chi::u32 method, chi::LoadTaskArchive& archive, 
                        hipc::FullPtr<chi::Task>& task_ptr) {
  auto* ipc_manager = CHI_IPC;
  
  switch (method) {
    default: {
      // Unknown method - do nothing
      break;
    }
  }
}

void Runtime::NewCopy(chi::u32 method, const hipc::FullPtr<chi::Task>& orig_task,
                       hipc::FullPtr<chi::Task>& dup_task, bool deep) {
  auto* ipc_manager = CHI_IPC;
  if (!ipc_manager) {
    return;
  }
  
  switch (method) {
    default: {
      // For unknown methods, create base Task copy
      auto typed_task = ipc_manager->NewTask<chi::Task>();
      if (!typed_task.IsNull()) {
        typed_task->Copy(orig_task);
        dup_task = typed_task;  // Already chi::Task type
      }
      break;
    }
  }
  
  (void)deep;    // Deep copy parameter reserved for future use
}

void Runtime::Aggregate(chi::u32 method, hipc::FullPtr<chi::Task> origin_task,
                         hipc::FullPtr<chi::Task> replica_task) {
  switch (method) {
    default: {
      // For unknown methods, use base Task Copy
      origin_task->Copy(replica_task);
      break;
    }
  }
}

} // namespace external_test::simple_mod
