import type { SubgraphData } from './types'

export function createVisualAgentLoopSubgraph(): SubgraphData {
  return {
    node_meta: {
      loop_in: {
        id: 'loop_in',
        type: 'SubnetInput',
        params: {},
        pos: [40, 220],
        inputs: [],
        outputs: ['prompt', 'system', 'model', 'tools', 'max_tokens', 'max_iter'],
        input_types: {},
        output_types: {
          prompt: 'Text',
          system: 'Text',
          model: 'Model',
          tools: 'List',
          max_tokens: 'Int',
          max_iter: 'Int',
        },
        input_defaults: {},
      },
      messages: {
        id: 'messages',
        type: 'AgentMessages',
        params: {},
        pos: [300, 120],
        inputs: ['prompt'],
        outputs: ['messages'],
        input_types: { prompt: 'Text' },
        output_types: { messages: 'List' },
        input_defaults: {},
      },
      chat: {
        id: 'chat',
        type: 'AgentChatStep',
        params: {},
        pos: [560, 100],
        inputs: ['messages', 'system', 'model', 'tools', 'max_tokens'],
        outputs: ['assistant_text', 'tool_calls', 'stop_reason', 'step'],
        input_types: {
          messages: 'List',
          system: 'Text',
          model: 'Model',
          tools: 'List',
          max_tokens: 'Int',
        },
        output_types: {
          assistant_text: 'Text',
          tool_calls: 'List',
          stop_reason: 'Text',
          step: 'Dict',
        },
        input_defaults: { model: 'claude-sonnet-4-6', max_tokens: 1024 },
      },
      iteration: {
        id: 'iteration',
        type: 'AgentIteration',
        params: { start: 1 },
        pos: [560, 360],
        inputs: ['start'],
        outputs: ['iteration'],
        input_types: { start: 'Int' },
        output_types: { iteration: 'Int' },
        input_defaults: { start: 1 },
      },
      dispatch: {
        id: 'dispatch',
        type: 'ToolDispatch',
        params: {},
        pos: [840, 80],
        inputs: ['tool_calls', 'tools'],
        outputs: ['tool_results', 'steps'],
        input_types: { tool_calls: 'List', tools: 'List' },
        output_types: { tool_results: 'List', steps: 'List' },
        input_defaults: {},
      },
      stop: {
        id: 'stop',
        type: 'AgentStopCheck',
        params: {},
        pos: [840, 330],
        inputs: ['stop_reason', 'tool_calls', 'iteration', 'max_iter'],
        outputs: ['continue', 'done', 'reason'],
        input_types: {
          stop_reason: 'Text',
          tool_calls: 'List',
          iteration: 'Int',
          max_iter: 'Int',
        },
        output_types: { continue: 'Bool', done: 'Bool', reason: 'Text' },
        input_defaults: { iteration: 1, max_iter: 5 },
      },
      append: {
        id: 'append',
        type: 'AgentAppendMessages',
        params: {},
        pos: [1120, 120],
        inputs: ['messages', 'model', 'assistant_text', 'tool_calls', 'tool_results'],
        outputs: ['messages'],
        input_types: {
          messages: 'List',
          model: 'Model',
          assistant_text: 'Text',
          tool_calls: 'List',
          tool_results: 'List',
        },
        output_types: { messages: 'List' },
        input_defaults: { model: 'claude-sonnet-4-6' },
      },
      final: {
        id: 'final',
        type: 'AgentFinalAnswer',
        params: {},
        pos: [1400, 150],
        inputs: ['messages', 'system', 'model', 'max_tokens', 'assistant_text', 'stop_reason', 'reason', 'tool_calls'],
        outputs: ['result', 'step'],
        input_types: {
          messages: 'List',
          system: 'Text',
          model: 'Model',
          max_tokens: 'Int',
          assistant_text: 'Text',
          stop_reason: 'Text',
          reason: 'Text',
          tool_calls: 'List',
        },
        output_types: { result: 'Text', step: 'Dict' },
        input_defaults: { model: 'claude-sonnet-4-6', max_tokens: 1024 },
      },
      loop_out: {
        id: 'loop_out',
        type: 'SubnetOutput',
        params: {},
        pos: [1680, 180],
        inputs: ['result', 'steps'],
        outputs: [],
        input_types: { result: 'Text', steps: 'List' },
        output_types: {},
        input_defaults: {},
      },
    },
    edges: [
      { from: 'loop_in', from_port: 'prompt', to: 'messages', to_port: 'prompt' },
      { from: 'messages', from_port: 'messages', to: 'chat', to_port: 'messages' },
      { from: 'loop_in', from_port: 'system', to: 'chat', to_port: 'system' },
      { from: 'loop_in', from_port: 'model', to: 'chat', to_port: 'model' },
      { from: 'loop_in', from_port: 'tools', to: 'chat', to_port: 'tools' },
      { from: 'loop_in', from_port: 'max_tokens', to: 'chat', to_port: 'max_tokens' },
      { from: 'chat', from_port: 'tool_calls', to: 'dispatch', to_port: 'tool_calls' },
      { from: 'loop_in', from_port: 'tools', to: 'dispatch', to_port: 'tools' },
      { from: 'messages', from_port: 'messages', to: 'append', to_port: 'messages' },
      { from: 'loop_in', from_port: 'model', to: 'append', to_port: 'model' },
      { from: 'chat', from_port: 'assistant_text', to: 'append', to_port: 'assistant_text' },
      { from: 'chat', from_port: 'tool_calls', to: 'append', to_port: 'tool_calls' },
      { from: 'dispatch', from_port: 'tool_results', to: 'append', to_port: 'tool_results' },
      { from: 'chat', from_port: 'stop_reason', to: 'stop', to_port: 'stop_reason' },
      { from: 'chat', from_port: 'tool_calls', to: 'stop', to_port: 'tool_calls' },
      { from: 'iteration', from_port: 'iteration', to: 'stop', to_port: 'iteration' },
      { from: 'loop_in', from_port: 'max_iter', to: 'stop', to_port: 'max_iter' },
      { from: 'append', from_port: 'messages', to: 'final', to_port: 'messages' },
      { from: 'loop_in', from_port: 'system', to: 'final', to_port: 'system' },
      { from: 'loop_in', from_port: 'model', to: 'final', to_port: 'model' },
      { from: 'loop_in', from_port: 'max_tokens', to: 'final', to_port: 'max_tokens' },
      { from: 'chat', from_port: 'assistant_text', to: 'final', to_port: 'assistant_text' },
      { from: 'chat', from_port: 'stop_reason', to: 'final', to_port: 'stop_reason' },
      { from: 'chat', from_port: 'tool_calls', to: 'final', to_port: 'tool_calls' },
      { from: 'stop', from_port: 'reason', to: 'final', to_port: 'reason' },
      { from: 'final', from_port: 'result', to: 'loop_out', to_port: 'result' },
      { from: 'dispatch', from_port: 'steps', to: 'loop_out', to_port: 'steps' },
    ],
  }
}
