"""Project templates for CLI."""
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from typing import List


PROJECT_TEMPLATES: dict[str, dict[str, str]] = {
    "single-agent-api": {
        "README.md": "# Single Agent API\n\nGenerated by `logos-adk project new`.\n",
        "app.py": """from logos_adk import Agent, create_app

agent = Agent("support-bot", model="mock")
app = create_app([agent], require_workspace=True)
""",
        "agent.yaml": """name: support-bot
model: gpt-4o-mini
system_prompt: |
  You are the primary internal support agent.
security:
  input_max_length: 8000
  output_max_length: 4000
state:
  backend: sqlite
  path: .logos_adk/support-state.db
scaling:
  task_queue:
    backend: sqlite
    path: .logos_adk/support-tasks.db
    max_retries: 2
    idempotency_ttl_seconds: 86400
""",
    },
    "rag-service": {
        "README.md": "# RAG Service\n\nGenerated by `logos-adk project new`.\n",
        "app.py": """from logos_adk import Agent, create_app

agent = Agent("knowledge-bot", model="mock")
app = create_app([agent], require_workspace=True)
""",
        "agent.yaml": """name: knowledge-bot
model: claude-sonnet-4-20250514
system_prompt: |
  Answer only from the indexed workspace knowledge base.
security:
  input_max_length: 12000
  output_max_length: 4000
state:
  backend: sqlite
  path: .logos_adk/rag-state.db
scaling:
  task_queue:
    backend: sqlite
    path: .logos_adk/rag-tasks.db
    max_retries: 3
""",
    },
    "workflow-app": {
        "README.md": "# Workflow App\n\nGenerated by `logos-adk project new`.\n",
        "app.py": """from logos_adk import Agent, create_app

agent = Agent("workflow-worker", model="mock")
app = create_app([agent], require_workspace=True)
""",
        "agent.yaml": """name: workflow-worker
model: gpt-4o-mini
system_prompt: |
  Execute the current workflow step and persist checkpoint-safe output.
security:
  output_max_length: 3000
state:
  backend: sqlite
  path: .logos_adk/workflow-state.db
scaling:
  task_queue:
    backend: sqlite
    path: .logos_adk/workflow-tasks.db
    max_retries: 2
""",
    },
    "multi-agent-team": {
        "README.md": "# Multi Agent Team\n\nGenerated by `logos-adk project new`.\n",
        "app.py": """from logos_adk import Agent, create_app

analyst = Agent("analyst", model="mock")
writer = Agent("writer", model="mock")
app = create_app([analyst, writer], require_workspace=True)
""",
        "team.yaml": """name: revenue-team
agents:
  - analyst
  - writer
routing:
  default: analyst
security:
  output_max_length: 3000
""",
    },
}


def copy_project_template(template: str, destination: Path) -> List[Path]:
    """Copy project template files to destination.
    
    Args:
        template: Template name (e.g., 'single-agent-api')
        destination: Destination directory path
        
    Returns:
        List of created file paths
    """
    files = PROJECT_TEMPLATES[template]
    created: list[Path] = []
    destination.mkdir(parents=True, exist_ok=True)
    
    for relative_path, content in files.items():
        target = destination / relative_path
        target.parent.mkdir(parents=True, exist_ok=True)
        target.write_text(content)
        created.append(target)
    
    return created


__all__ = ["PROJECT_TEMPLATES", "copy_project_template"]
