/**
 * Auto-generated execution implementation for core 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 "wrp_cte/core/core_runtime.h"
#include "wrp_cte/core/autogen/core_methods.h"
#include <chimaera/chimaera.h>

namespace wrp_cte::core {

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

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

  // 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) {
    case Method::kCreate: {
      Create(task_ptr.Cast<CreateTask>(), rctx);
      break;
    }
    case Method::kDestroy: {
      Destroy(task_ptr.Cast<DestroyTask>(), rctx);
      break;
    }
    case Method::kRegisterTarget: {
      RegisterTarget(task_ptr.Cast<RegisterTargetTask>(), rctx);
      break;
    }
    case Method::kUnregisterTarget: {
      UnregisterTarget(task_ptr.Cast<UnregisterTargetTask>(), rctx);
      break;
    }
    case Method::kListTargets: {
      ListTargets(task_ptr.Cast<ListTargetsTask>(), rctx);
      break;
    }
    case Method::kStatTargets: {
      StatTargets(task_ptr.Cast<StatTargetsTask>(), rctx);
      break;
    }
    case Method::kGetOrCreateTag: {
      GetOrCreateTag(task_ptr.Cast<core::GetOrCreateTagTask<core::CreateParams>>(), rctx);
      break;
    }
    case Method::kPutBlob: {
      PutBlob(task_ptr.Cast<PutBlobTask>(), rctx);
      break;
    }
    case Method::kGetBlob: {
      GetBlob(task_ptr.Cast<GetBlobTask>(), rctx);
      break;
    }
    case Method::kReorganizeBlob: {
      ReorganizeBlob(task_ptr.Cast<ReorganizeBlobTask>(), rctx);
      break;
    }
    case Method::kDelBlob: {
      DelBlob(task_ptr.Cast<DelBlobTask>(), rctx);
      break;
    }
    case Method::kDelTag: {
      DelTag(task_ptr.Cast<DelTagTask>(), rctx);
      break;
    }
    case Method::kGetTagSize: {
      GetTagSize(task_ptr.Cast<GetTagSizeTask>(), rctx);
      break;
    }
    case Method::kPollTelemetryLog: {
      PollTelemetryLog(task_ptr.Cast<PollTelemetryLogTask>(), rctx);
      break;
    }
    case Method::kGetBlobScore: {
      GetBlobScore(task_ptr.Cast<GetBlobScoreTask>(), rctx);
      break;
    }
    case Method::kGetBlobSize: {
      GetBlobSize(task_ptr.Cast<GetBlobSizeTask>(), rctx);
      break;
    }
    case Method::kGetContainedBlobs: {
      GetContainedBlobs(task_ptr.Cast<GetContainedBlobsTask>(), rctx);
      break;
    }
    case Method::kTagQuery: {
      TagQuery(task_ptr.Cast<TagQueryTask>(), rctx);
      break;
    }
    case Method::kBlobQuery: {
      BlobQuery(task_ptr.Cast<BlobQueryTask>(), rctx);
      break;
    }
    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) {
    case Method::kCreate: {
      ipc_manager->DelTask(task_ptr.Cast<CreateTask>());
      break;
    }
    case Method::kDestroy: {
      ipc_manager->DelTask(task_ptr.Cast<DestroyTask>());
      break;
    }
    case Method::kRegisterTarget: {
      ipc_manager->DelTask(task_ptr.Cast<RegisterTargetTask>());
      break;
    }
    case Method::kUnregisterTarget: {
      ipc_manager->DelTask(task_ptr.Cast<UnregisterTargetTask>());
      break;
    }
    case Method::kListTargets: {
      ipc_manager->DelTask(task_ptr.Cast<ListTargetsTask>());
      break;
    }
    case Method::kStatTargets: {
      ipc_manager->DelTask(task_ptr.Cast<StatTargetsTask>());
      break;
    }
    case Method::kGetOrCreateTag: {
      ipc_manager->DelTask(task_ptr.Cast<core::GetOrCreateTagTask<core::CreateParams>>());
      break;
    }
    case Method::kPutBlob: {
      ipc_manager->DelTask(task_ptr.Cast<PutBlobTask>());
      break;
    }
    case Method::kGetBlob: {
      ipc_manager->DelTask(task_ptr.Cast<GetBlobTask>());
      break;
    }
    case Method::kReorganizeBlob: {
      ipc_manager->DelTask(task_ptr.Cast<ReorganizeBlobTask>());
      break;
    }
    case Method::kDelBlob: {
      ipc_manager->DelTask(task_ptr.Cast<DelBlobTask>());
      break;
    }
    case Method::kDelTag: {
      ipc_manager->DelTask(task_ptr.Cast<DelTagTask>());
      break;
    }
    case Method::kGetTagSize: {
      ipc_manager->DelTask(task_ptr.Cast<GetTagSizeTask>());
      break;
    }
    case Method::kPollTelemetryLog: {
      ipc_manager->DelTask(task_ptr.Cast<PollTelemetryLogTask>());
      break;
    }
    case Method::kGetBlobScore: {
      ipc_manager->DelTask(task_ptr.Cast<GetBlobScoreTask>());
      break;
    }
    case Method::kGetBlobSize: {
      ipc_manager->DelTask(task_ptr.Cast<GetBlobSizeTask>());
      break;
    }
    case Method::kGetContainedBlobs: {
      ipc_manager->DelTask(task_ptr.Cast<GetContainedBlobsTask>());
      break;
    }
    case Method::kTagQuery: {
      ipc_manager->DelTask(task_ptr.Cast<TagQueryTask>());
      break;
    }
    case Method::kBlobQuery: {
      ipc_manager->DelTask(task_ptr.Cast<BlobQueryTask>());
      break;
    }
    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) {
    case Method::kCreate: {
      auto typed_task = task_ptr.Cast<CreateTask>();
      archive << *typed_task;
      break;
    }
    case Method::kDestroy: {
      auto typed_task = task_ptr.Cast<DestroyTask>();
      archive << *typed_task;
      break;
    }
    case Method::kRegisterTarget: {
      auto typed_task = task_ptr.Cast<RegisterTargetTask>();
      archive << *typed_task;
      break;
    }
    case Method::kUnregisterTarget: {
      auto typed_task = task_ptr.Cast<UnregisterTargetTask>();
      archive << *typed_task;
      break;
    }
    case Method::kListTargets: {
      auto typed_task = task_ptr.Cast<ListTargetsTask>();
      archive << *typed_task;
      break;
    }
    case Method::kStatTargets: {
      auto typed_task = task_ptr.Cast<StatTargetsTask>();
      archive << *typed_task;
      break;
    }
    case Method::kGetOrCreateTag: {
      auto typed_task = task_ptr.Cast<core::GetOrCreateTagTask<core::CreateParams>>();
      archive << *typed_task;
      break;
    }
    case Method::kPutBlob: {
      auto typed_task = task_ptr.Cast<PutBlobTask>();
      archive << *typed_task;
      break;
    }
    case Method::kGetBlob: {
      auto typed_task = task_ptr.Cast<GetBlobTask>();
      archive << *typed_task;
      break;
    }
    case Method::kReorganizeBlob: {
      auto typed_task = task_ptr.Cast<ReorganizeBlobTask>();
      archive << *typed_task;
      break;
    }
    case Method::kDelBlob: {
      auto typed_task = task_ptr.Cast<DelBlobTask>();
      archive << *typed_task;
      break;
    }
    case Method::kDelTag: {
      auto typed_task = task_ptr.Cast<DelTagTask>();
      archive << *typed_task;
      break;
    }
    case Method::kGetTagSize: {
      auto typed_task = task_ptr.Cast<GetTagSizeTask>();
      archive << *typed_task;
      break;
    }
    case Method::kPollTelemetryLog: {
      auto typed_task = task_ptr.Cast<PollTelemetryLogTask>();
      archive << *typed_task;
      break;
    }
    case Method::kGetBlobScore: {
      auto typed_task = task_ptr.Cast<GetBlobScoreTask>();
      archive << *typed_task;
      break;
    }
    case Method::kGetBlobSize: {
      auto typed_task = task_ptr.Cast<GetBlobSizeTask>();
      archive << *typed_task;
      break;
    }
    case Method::kGetContainedBlobs: {
      auto typed_task = task_ptr.Cast<GetContainedBlobsTask>();
      archive << *typed_task;
      break;
    }
    case Method::kTagQuery: {
      auto typed_task = task_ptr.Cast<TagQueryTask>();
      archive << *typed_task;
      break;
    }
    case Method::kBlobQuery: {
      auto typed_task = task_ptr.Cast<BlobQueryTask>();
      archive << *typed_task;
      break;
    }
    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) {
    case Method::kCreate: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<CreateTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<CreateTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kDestroy: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<DestroyTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<DestroyTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kRegisterTarget: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<RegisterTargetTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<RegisterTargetTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kUnregisterTarget: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<UnregisterTargetTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<UnregisterTargetTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kListTargets: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<ListTargetsTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<ListTargetsTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kStatTargets: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<StatTargetsTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<StatTargetsTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kGetOrCreateTag: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<core::GetOrCreateTagTask<core::CreateParams>>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<core::GetOrCreateTagTask<core::CreateParams>>();
      archive >> *typed_task;
      break;
    }
    case Method::kPutBlob: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<PutBlobTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<PutBlobTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kGetBlob: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<GetBlobTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<GetBlobTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kReorganizeBlob: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<ReorganizeBlobTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<ReorganizeBlobTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kDelBlob: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<DelBlobTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<DelBlobTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kDelTag: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<DelTagTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<DelTagTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kGetTagSize: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<GetTagSizeTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<GetTagSizeTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kPollTelemetryLog: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<PollTelemetryLogTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<PollTelemetryLogTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kGetBlobScore: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<GetBlobScoreTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<GetBlobScoreTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kGetBlobSize: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<GetBlobSizeTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<GetBlobSizeTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kGetContainedBlobs: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<GetContainedBlobsTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<GetContainedBlobsTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kTagQuery: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<TagQueryTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<TagQueryTask>();
      archive >> *typed_task;
      break;
    }
    case Method::kBlobQuery: {
      // Allocate task using typed NewTask if not already allocated
      if (task_ptr.IsNull()) {
        task_ptr = ipc_manager->NewTask<BlobQueryTask>().template Cast<chi::Task>();
      }
      auto typed_task = task_ptr.Cast<BlobQueryTask>();
      archive >> *typed_task;
      break;
    }
    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) {
    case Method::kCreate: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<CreateTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<CreateTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kDestroy: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<DestroyTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<DestroyTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kRegisterTarget: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<RegisterTargetTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<RegisterTargetTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kUnregisterTarget: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<UnregisterTargetTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<UnregisterTargetTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kListTargets: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<ListTargetsTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<ListTargetsTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kStatTargets: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<StatTargetsTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<StatTargetsTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kGetOrCreateTag: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<core::GetOrCreateTagTask<core::CreateParams>>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<core::GetOrCreateTagTask<core::CreateParams>>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kPutBlob: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<PutBlobTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<PutBlobTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kGetBlob: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<GetBlobTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<GetBlobTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kReorganizeBlob: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<ReorganizeBlobTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<ReorganizeBlobTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kDelBlob: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<DelBlobTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<DelBlobTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kDelTag: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<DelTagTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<DelTagTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kGetTagSize: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<GetTagSizeTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<GetTagSizeTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kPollTelemetryLog: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<PollTelemetryLogTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<PollTelemetryLogTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kGetBlobScore: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<GetBlobScoreTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<GetBlobScoreTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kGetBlobSize: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<GetBlobSizeTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<GetBlobSizeTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kGetContainedBlobs: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<GetContainedBlobsTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<GetContainedBlobsTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kTagQuery: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<TagQueryTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<TagQueryTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    case Method::kBlobQuery: {
      // Allocate new task using SHM default constructor
      auto typed_task = ipc_manager->NewTask<BlobQueryTask>();
      if (!typed_task.IsNull()) {
        // Copy base Task fields first
        typed_task.template Cast<chi::Task>()->Copy(orig_task);
        // Then copy task-specific fields
        typed_task->Copy(orig_task.Cast<BlobQueryTask>());
        // Cast to base Task type for return
        dup_task = typed_task.template Cast<chi::Task>();
      }
      break;
    }
    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) {
    case Method::kCreate: {
      auto typed_origin = origin_task.Cast<CreateTask>();
      auto typed_replica = replica_task.Cast<CreateTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kDestroy: {
      auto typed_origin = origin_task.Cast<DestroyTask>();
      auto typed_replica = replica_task.Cast<DestroyTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kRegisterTarget: {
      auto typed_origin = origin_task.Cast<RegisterTargetTask>();
      auto typed_replica = replica_task.Cast<RegisterTargetTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kUnregisterTarget: {
      auto typed_origin = origin_task.Cast<UnregisterTargetTask>();
      auto typed_replica = replica_task.Cast<UnregisterTargetTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kListTargets: {
      auto typed_origin = origin_task.Cast<ListTargetsTask>();
      auto typed_replica = replica_task.Cast<ListTargetsTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kStatTargets: {
      auto typed_origin = origin_task.Cast<StatTargetsTask>();
      auto typed_replica = replica_task.Cast<StatTargetsTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kGetOrCreateTag: {
      auto typed_origin = origin_task.Cast<core::GetOrCreateTagTask<core::CreateParams>>();
      auto typed_replica = replica_task.Cast<core::GetOrCreateTagTask<core::CreateParams>>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kPutBlob: {
      auto typed_origin = origin_task.Cast<PutBlobTask>();
      auto typed_replica = replica_task.Cast<PutBlobTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kGetBlob: {
      auto typed_origin = origin_task.Cast<GetBlobTask>();
      auto typed_replica = replica_task.Cast<GetBlobTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kReorganizeBlob: {
      auto typed_origin = origin_task.Cast<ReorganizeBlobTask>();
      auto typed_replica = replica_task.Cast<ReorganizeBlobTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kDelBlob: {
      auto typed_origin = origin_task.Cast<DelBlobTask>();
      auto typed_replica = replica_task.Cast<DelBlobTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kDelTag: {
      auto typed_origin = origin_task.Cast<DelTagTask>();
      auto typed_replica = replica_task.Cast<DelTagTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kGetTagSize: {
      auto typed_origin = origin_task.Cast<GetTagSizeTask>();
      auto typed_replica = replica_task.Cast<GetTagSizeTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kPollTelemetryLog: {
      auto typed_origin = origin_task.Cast<PollTelemetryLogTask>();
      auto typed_replica = replica_task.Cast<PollTelemetryLogTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kGetBlobScore: {
      auto typed_origin = origin_task.Cast<GetBlobScoreTask>();
      auto typed_replica = replica_task.Cast<GetBlobScoreTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kGetBlobSize: {
      auto typed_origin = origin_task.Cast<GetBlobSizeTask>();
      auto typed_replica = replica_task.Cast<GetBlobSizeTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kGetContainedBlobs: {
      auto typed_origin = origin_task.Cast<GetContainedBlobsTask>();
      auto typed_replica = replica_task.Cast<GetContainedBlobsTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kTagQuery: {
      auto typed_origin = origin_task.Cast<TagQueryTask>();
      auto typed_replica = replica_task.Cast<TagQueryTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    case Method::kBlobQuery: {
      auto typed_origin = origin_task.Cast<BlobQueryTask>();
      auto typed_replica = replica_task.Cast<BlobQueryTask>();
      // Call base Task aggregate to propagate return codes
      origin_task->Aggregate(replica_task);
      // Use SFINAE-based macro to call task-specific Aggregate if available, otherwise Copy
      CHI_AGGREGATE_OR_COPY(typed_origin, typed_replica);
      break;
    }
    default: {
      // For unknown methods, use base Task Aggregate (which also propagates return codes)
      origin_task->Aggregate(replica_task);
      break;
    }
  }
}

} // namespace wrp_cte::core
