# Copyright (c) 2025 Patrick Motsch
# All rights reserved.
"""
Base renderer class for code format renderers.
"""

from abc import abstractmethod
from .documentRendererBaseTemplate import BaseRenderer
from modules.datamodels.datamodelDocument import RenderedDocument
from typing import Dict, Any, List, Optional
import logging

logger = logging.getLogger(__name__)

class BaseCodeRenderer(BaseRenderer):
    """Base class for code format renderers."""
    
    @abstractmethod
    async def renderCodeFiles(
        self, 
        codeFiles: List[Dict[str, Any]], 
        metadata: Dict[str, Any],
        userPrompt: str = None
    ) -> List[RenderedDocument]:
        """
        Render code files to format-specific output.
        
        Args:
            codeFiles: List of file dictionaries with:
                - filename: str
                - fileType: str (json, csv, xml, etc.)
                - content: str (generated code)
                - id: str (optional)
            metadata: Project metadata (language, projectType, etc.)
            userPrompt: Original user prompt
            
        Returns:
            List of RenderedDocument objects (can be 1..n files)
        """
        pass
    
    def _validateCodeFile(self, codeFile: Dict[str, Any]) -> bool:
        """Validate code file structure."""
        required = ['filename', 'fileType', 'content']
        return all(key in codeFile for key in required)
