/**
 * Implementation Graph - Apply code changes AND create PR
 * 
 * Flow:
 * 1. setup - Clone repos and init git baseline
 * 2. implement_code - Apply changes, commit, push to branch
 * 3. generate_tests - Generate test cases
 * 4. create_pr - Create GitHub Pull Request
 * 5. finalize - Upload results to API
 */

import { setupNode } from '../code-analysis/nodes/setup-node.js';
import { implementCodeNode } from '../code-analysis/nodes/generate-code-node.js';
import { generateTestCasesNode } from '../code-analysis/nodes/generate-test-cases-node.js';
import { createPRNode } from '../code-analysis/nodes/create-pr-node.js';
import { finalizeNode } from '../code-analysis/nodes/finalize-node.js';
import { implementationStateSchema } from './state.js';

export function buildImplementationGraph(graph) {
  graph.setStateSchema(implementationStateSchema);
  
  graph
    .addNode('setup', setupNode)                   // ← Reused from analysis!
    .addNode('implement_code', implementCodeNode)  // ← Real changes + push
    .addNode('generate_test_cases', generateTestCasesNode)  // ← Generate human-readable test specs
    .addNode('create_pr', createPRNode)            // ← Create GitHub PR
    .addNode('finalize', finalizeNode)             // ← Reused from analysis!
    .setEntryPoint('setup')
    .addEdge('setup', 'implement_code')
    .addEdge('implement_code', 'generate_test_cases')
    .addEdge('generate_test_cases', 'create_pr')
    .addEdge('create_pr', 'finalize');
  
  return graph;
}
