// src/hooks/operations/command-view/utils/transformCommandViewData.ts
function transformCommandViewData(data) {
  const nodes = [
    // Map triggers (resourceId -> id)
    ...data.triggers.map((trigger) => ({
      id: trigger.resourceId,
      type: "trigger",
      name: trigger.name,
      description: trigger.description,
      status: trigger.status,
      triggerType: trigger.triggerType,
      webhookPath: trigger.webhookPath,
      schedule: trigger.schedule
    })),
    // Map agents (resourceId -> id)
    ...data.agents.map((agent) => {
      const agentWithStats = agent;
      return {
        id: agent.resourceId,
        type: "agent",
        name: agent.name,
        description: agent.description,
        status: agent.status,
        modelProvider: agent.modelProvider,
        modelId: agent.modelId,
        toolCount: agent.toolCount,
        hasKnowledgeMap: agent.hasKnowledgeMap,
        hasMemory: agent.hasMemory,
        stats: agentWithStats.stats || null
        // Preserve stats if present
      };
    }),
    // Map workflows (resourceId -> id)
    ...data.workflows.map((workflow) => {
      const workflowWithStats = workflow;
      return {
        id: workflow.resourceId,
        type: "workflow",
        name: workflow.name,
        description: workflow.description,
        status: workflow.status,
        stepCount: workflow.stepCount,
        entryPoint: workflow.entryPoint,
        stats: workflowWithStats.stats || null
        // Preserve stats if present
      };
    }),
    // Map integrations (resourceId -> id)
    ...data.integrations.map((integration) => ({
      id: integration.resourceId,
      type: "integration",
      name: integration.name,
      description: integration.description,
      status: integration.status,
      provider: integration.provider,
      connectionStatus: "connected",
      // Default - runtime status not yet available
      credentialName: integration.credentialName
    })),
    // Map external resources (resourceId -> id)
    ...(data.externalResources ?? []).map((external) => ({
      id: external.resourceId,
      type: "external",
      name: external.name,
      description: external.description,
      status: external.status,
      platform: external.platform,
      platformUrl: external.platformUrl,
      externalId: external.externalId
    })),
    // Map human checkpoints to human nodes (resourceId -> id)
    ...(data.humanCheckpoints ?? []).map((humanCheckpoint) => {
      const checkpointWithStats = humanCheckpoint;
      return {
        id: humanCheckpoint.resourceId,
        type: "human",
        name: humanCheckpoint.name,
        description: humanCheckpoint.description ?? "",
        status: humanCheckpoint.status,
        stats: checkpointWithStats.stats || null
        // Preserve stats if present
      };
    })
  ];
  const edges = data.edges.map((edge, index) => ({
    id: edge.id || `edge-${index}`,
    source: edge.source,
    target: edge.target,
    relationship: edge.relationship
  }));
  return { nodes, edges };
}

export { transformCommandViewData };
