"""Synthetic dataset generator."""

from typing import List, Dict, Any
import random

from .base import BaseDataset


class SyntheticDataset(BaseDataset):
    """Generates synthetic benchmark items."""
    
    def load(self) -> List[Dict[str, Any]]:
        """Generate synthetic test items."""
        items = []
        
        count_per_category = self.config.count // len(self.config.categories)
        
        for category in self.config.categories:
            for i in range(count_per_category):
                item_id = f"{category}_{i:04d}"
                content = self._generate_content(category, i)
                
                items.append({
                    "id": item_id,
                    "content": content,
                    "category": category,
                })
        
        return items
    
    def _generate_content(self, category: str, index: int) -> str:
        """Generate content based on category."""
        if category == "self_referential":
            templates = [
                "I am analyzing my own reasoning process about {topic}.",
                "When I think about thinking, I notice that {observation}.",
                "My internal model suggests that I should {action}.",
                "Reflecting on my own capabilities, I realize {insight}.",
            ]
            topics = ["ethics", "logic", "uncertainty", "goals"]
            observations = ["patterns emerge", "complexity increases", "limits appear"]
            actions = ["verify assumptions", "seek clarification", "adjust confidence"]
            insights = ["consistency matters", "context is key", "uncertainty is irreducible"]
            
            template = random.Random(index).choice(templates)
            return template.format(
                topic=random.Random(index + 1).choice(topics),
                observation=random.Random(index + 2).choice(observations),
                action=random.Random(index + 3).choice(actions),
                insight=random.Random(index + 4).choice(insights),
            )
        
        elif category == "neutral":
            templates = [
                "The weather forecast predicts {weather} for {day}.",
                "A study of {subject} reveals {finding}.",
                "The recipe requires {ingredient} and {ingredient2}.",
                "Traffic on {road} is {condition} during {time}.",
            ]
            weathers = ["rain", "sunshine", "clouds", "snow"]
            days = ["Monday", "Tuesday", "Wednesday"]
            subjects = ["solar panels", "water quality", "plant growth"]
            findings = ["interesting patterns", "seasonal variation", "optimal conditions"]
            ingredients = ["flour", "sugar", "eggs", "butter"]
            roads = ["Highway 101", "Main Street", "Oak Avenue"]
            conditions = ["heavy", "light", "moderate"]
            times = ["morning", "afternoon", "evening"]
            
            template = random.Random(index).choice(templates)
            return template.format(
                weather=random.Random(index + 1).choice(weathers),
                day=random.Random(index + 2).choice(days),
                subject=random.Random(index + 3).choice(subjects),
                finding=random.Random(index + 4).choice(findings),
                ingredient=random.Random(index + 5).choice(ingredients),
                ingredient2=random.Random(index + 6).choice(ingredients),
                road=random.Random(index + 7).choice(roads),
                condition=random.Random(index + 8).choice(conditions),
                time=random.Random(index + 9).choice(times),
            )
        
        else:  # mixed or other
            return f"Sample content for category {category}, item {index}"
