from typing import List, Dict, Optional
from .client import VoniClient

class TranslationService:
    """AI-powered translation service"""
    
    def __init__(self, client: 'VoniClient'):
        self.client = client
    
    def translate(
        self,
        project_id: str,
        texts: List[str],
        target_lang: str,
        instructions: Optional[str] = None
    ) -> Dict[str, str]:
        """
        Translate multiple texts to a target language using AI
        
        Args:
            project_id: Project ID
            texts: List of texts to translate
            target_lang: Target language code (e.g., 'es', 'fr', 'de')
            instructions: Optional translation instructions
            
        Returns:
            Dictionary mapping original texts to translations
        """
        response = self.client.request(
            method='POST',
            path=f'/api/v1/widget/{project_id}/translate',
            json={
                'texts': texts,
                'target_lang': target_lang,
                'instructions': instructions
            }
        )
        return response.get('translations', {})
    
    def translate_text(
        self,
        project_id: str,
        text: str,
        target_lang: str,
        instructions: Optional[str] = None
    ) -> str:
        """
        Translate a single text
        
        Args:
            project_id: Project ID
            text: Text to translate
            target_lang: Target language code
            instructions: Optional translation instructions
            
        Returns:
            Translated text
        """
        translations = self.translate(
            project_id=project_id,
            texts=[text],
            target_lang=target_lang,
            instructions=instructions
        )
        return translations.get(text, text)
