"""
Utility functions for templating setup scripts with dynamic parameters.
"""

from pathlib import Path
from typing import Any, Dict

from jinja2 import Environment, FileSystemLoader


def render_setup_script(template_path: Path, context: Dict[str, Any]) -> str:
    """
    Render a setup script template with the given context.
    
    Args:
        template_path: Path to the Jinja2 template file
        context: Dictionary of variables to pass to the template
        
    Returns:
        Rendered script content as a string
    """
    if not template_path.exists():
        raise FileNotFoundError(f"Template file not found: {template_path}")
    
    # Create Jinja2 environment
    env = Environment(
        loader=FileSystemLoader(template_path.parent),
        trim_blocks=True,
        lstrip_blocks=True
    )
    
    # Load and render template
    template = env.get_template(template_path.name)
    return template.render(**context)


def get_template_path(agent_dir: Path, template_name: str = "setup.sh.j2") -> Path:
    """
    Get the path to a template file in an agent directory.
    
    Args:
        agent_dir: Path to the agent directory
        template_name: Name of the template file
        
    Returns:
        Path to the template file
    """
    return agent_dir / template_name 