import type {
  AgentChatActionBindingsInput,
  BuildAgentChatInteractionControllerInputOptions,
} from '@/features/agent/presentation/agentChatInteractionInputTypes'

export function buildAgentChatActionBindingsInput({
  activeRun,
  buildingSendWorkspace,
  context,
  conv,
  loading,
  taskGraph,
  presentation,
  providerSessionState,
  store,
}: BuildAgentChatInteractionControllerInputOptions): AgentChatActionBindingsInput {
  return {
    runResultActions: {
      conversationId: conv.id,
      ...(conv.providerSessionId ? { sessionId: conv.providerSessionId } : {}),
      setConversationRun: store.setConversationRun,
      setSubmittedInteractionRuns: providerSessionState.setSubmittedInteractionRuns,
      recordLiveTraceEvent: providerSessionState.recordLiveTraceEvent,
      updateStreamingAssistantText: providerSessionState.updateStreamingAssistantText,
    },
    runInteractionActions: {
      conversationId: conv.id,
      ...(conv.providerSessionId ? { sessionId: conv.providerSessionId } : {}),
      actionableRun: presentation.actionableRun,
      interactionRuns: presentation.interactionRuns,
      approving: presentation.approvingActiveRun,
      setSubmittedInteractionRuns: providerSessionState.setSubmittedInteractionRuns,
      updateConversationRuntimeState: store.updateConversationRuntimeState,
      setConversationRun: store.setConversationRun,
    },
    planActions: {
      conversationId: conv.id,
      ...(conv.providerSessionId ? { sessionId: conv.providerSessionId } : {}),
      run: activeRun,
      snapshot: presentation.activePlanSnapshot,
      busy: providerSessionState.planActionBusy,
      dispatchSettings: taskGraph.planDispatchSettings,
      setBusy: providerSessionState.setPlanActionBusy,
      setConversationRun: store.setConversationRun,
      updateConversationRuntimeState: store.updateConversationRuntimeState,
      refetchPlanSnapshot: () => presentation.refetchActivePlanSnapshot(),
    },
    stopAction: {
      conversationId: conv.id,
      ...(conv.providerSessionId ? { sessionId: conv.providerSessionId } : {}),
      run: activeRun,
      loading,
      building: buildingSendWorkspace,
      stopping: presentation.stoppingActiveRun,
      stopRequestedBeforeRun: presentation.stopRequestedBeforeRun,
      generationProgressState: presentation.generationProgressState,
      activeSendAbortControllerRef: providerSessionState.activeSendAbortControllerRef,
      setPendingAssistantState: providerSessionState.setPendingAssistantState,
      resetStreamingAssistant: providerSessionState.resetStreamingAssistant,
      setConversationRun: store.setConversationRun,
      updateConversationRuntimeState: store.updateConversationRuntimeState,
    },
  }
}
