# BreakpointManagerService

Import it from `@grafloria/angular`.

BreakpointManager Service

Manages breakpoints for debugging diagram execution.

Features:
- Set/remove breakpoints on nodes
- Conditional breakpoints
- Enable/disable breakpoints
- Hit count tracking
- Breakpoint hit notifications

```ts
@Injectable({ providedIn: 'root' })
export class BreakpointManagerService
```

**Properties**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `breakpoints$` |  |  | Observable of all breakpoints. Emits whenever breakpoints change. |
| `breakpointHit$` |  |  | Observable of breakpoint hit events. Emits when a breakpoint is hit during execution. |

**Methods**

- `addBreakpoint( nodeId: string, type: BreakpointType, condition?: BreakpointCondition, conditionExpression?: string, metadata?: Record<string, any> ): Breakpoint` — Add breakpoint to node.
- `removeBreakpoint(breakpointId: string): boolean` — Remove breakpoint by ID.
- `removeBreakpointsForNode(nodeId: string): number` — Remove all breakpoints for node.
- `clearBreakpoints(): void` — Remove all breakpoints.
- `enableBreakpoint(breakpointId: string): void` — Enable breakpoint.
- `disableBreakpoint(breakpointId: string): void` — Disable breakpoint.
- `toggleBreakpoint(breakpointId: string): void` — Toggle breakpoint enabled/disabled.
- `getBreakpoint(breakpointId: string): Breakpoint | null` — Get breakpoint by ID.
- `getAllBreakpoints(): Breakpoint[]` — Get all breakpoints.
- `getBreakpointsForNode(nodeId: string): Breakpoint[]` — Get breakpoints for node.
- `hasBreakpoint(nodeId: string, type?: BreakpointType): boolean` — Check if node has breakpoint.
- `getBreakpointCount(): number` — Get breakpoint count.
- `getEnabledBreakpointCount(): number` — Get enabled breakpoint count.
- `shouldBreak(nodeId: string, type: BreakpointType, context?: any): boolean` — Check if breakpoint should hit at node. Call this during execution before/after node execution.
- `triggerBreakpointHit(breakpointId: string, context?: any): void` — Manually trigger breakpoint hit. Useful for testing or custom breakpoint logic.
- `resetHitCount(breakpointId: string): void` — Reset hit count for breakpoint.
- `resetAllHitCounts(): void` — Reset hit counts for all breakpoints.
- `getStats(): { total: number; enabled: number; disabled: number; byType: Record<BreakpointType, number>; totalHits: number; }` — Get breakpoint statistics.

**Example**

```typescript
constructor(
  private breakpointManager: BreakpointManagerService
) {}

setDebugBreakpoint(nodeId: string) {
  // Set breakpoint before node execution
  const breakpoint = this.breakpointManager.addBreakpoint(
    nodeId,
    BreakpointType.BEFORE
  );

  // Listen for hits
  this.breakpointManager.breakpointHit$.subscribe(event => {
    console.log('Breakpoint hit:', event.nodeId);
    // Pause execution, show debugger, etc.
  });
}

setConditionalBreakpoint(nodeId: string) {
  // Set conditional breakpoint
  this.breakpointManager.addBreakpoint(
    nodeId,
    BreakpointType.CONDITIONAL,
    (context) => context.value > 100,
    'value > 100'
  );
}
```
