export interface CodeBlock { readonly content: string; readonly language: string; readonly startLine: number; readonly endLine: number; readonly filePath: string; readonly metadata?: Record; } export interface CodeBlockBuilder { content(content: string): CodeBlockBuilder; language(language: string): CodeBlockBuilder; startLine(startLine: number): CodeBlockBuilder; endLine(endLine: number): CodeBlockBuilder; filePath(filePath: string): CodeBlockBuilder; metadata(metadata: Record): CodeBlockBuilder; build(): CodeBlock; } export class CodeBlockImpl implements CodeBlockBuilder { private block: any = {}; content(content: string): CodeBlockBuilder { this.block.content = content; return this; } language(language: string): CodeBlockBuilder { this.block.language = language; return this; } startLine(startLine: number): CodeBlockBuilder { this.block.startLine = startLine; return this; } endLine(endLine: number): CodeBlockBuilder { this.block.endLine = endLine; return this; } filePath(filePath: string): CodeBlockBuilder { this.block.filePath = filePath; return this; } metadata(metadata: Record): CodeBlockBuilder { this.block.metadata = metadata; return this; } build(): CodeBlock { if (!this.block.content || !this.block.language || this.block.startLine === undefined || this.block.endLine === undefined || !this.block.filePath) { throw new Error('Required fields missing for CodeBlock'); } if (this.block.startLine > this.block.endLine) { throw new Error('Start line cannot be greater than end line'); } const result: any = { content: this.block.content, language: this.block.language, startLine: this.block.startLine, endLine: this.block.endLine, filePath: this.block.filePath, }; if (this.block.metadata) { result.metadata = this.block.metadata; } return result; } }