"""
Greeting templates for the chatbot with shorter, more concise options
"""

from typing import Dict, List
from utils.agent_config import agent_config

class GreetingTemplates:
    """Collection of greeting templates for different scenarios"""
    
    # Standard greetings
    STANDARD_GREETINGS = {
        "first_time": [
            "Hi there! I'm {agent_name}, how can I help you today?",
            "Hello! How can {company_name} assist you today?",
            "Welcome! How can I help you with {company_name}'s services?",
            "Hello! I'm {agent_name} from {company_name}. How may I assist you?",
            "Welcome to {company_name}! I'm {agent_name}, your AI assistant. How can I help?"
        ],
        "returning": [
            "Welcome back! How can I help you today?",
            "Good to see you again! What can I help you with?",
            "Hello again! How can {company_name} assist you today?",
            "Nice to see you again! How can I assist you with {company_name}'s services?",
            "Welcome back! What brings you to {company_name} today?"
        ]
    }
    
    # Shorter greetings
    SHORT_GREETINGS = {
        "first_time": [
            "Hi! I'm {agent_name}, how can I help you?",
            "Hello! I'm {agent_name} from {company_name}. How can I assist you?",
            "Welcome! I'm {agent_name}, your AI assistant at {company_name}. How can I help?",
            "Hi there! I'm {agent_name}. What brings you to {company_name} today?",
            "Hello! I'm {agent_name}, your AI assistant. What can I help you with today?"
        ],
        "returning": [
            "Welcome back!",
            "Hello again!",
            "Good to see you again!",
            "Nice to see you again! How can I help?",
            "Welcome back! What can I assist you with today?"
        ]
    }
    
    # Context-aware greetings
    CONTEXT_GREETINGS = {
        "project_inquiry": [
            "Hi there! Looking to discuss a project with {company_name}?",
            "Hello! Interested in starting a project with us?"
        ],
        "technical": [
            "Hello! Need technical information about our services?",
            "Hi there! Looking for specific technical details?"
        ],
        "pricing": [
            "Hello! Interested in our pricing options?",
            "Hi there! Looking for cost information?"
        ],
        "scheduling": [
            "Hello! Would you like to schedule a meeting with our team?",
            "Hi there! Looking to book some time with us?"
        ]
    }
    
    @classmethod
    def get_greeting(cls, is_returning: bool = False, context_type: str = None, time_of_day: str = None) -> str:
        """
        Get an appropriate greeting based on context
        
        Args:
            is_returning: Whether this is a returning user
            context_type: Optional context type (project_inquiry, technical, pricing, scheduling)
            time_of_day: Optional time of day (morning, afternoon, evening)
            
        Returns:
            str: A greeting message
        """
        import random
        
        # If we have context type, use context-aware greeting
        if context_type and context_type in cls.CONTEXT_GREETINGS:
            greetings = cls.CONTEXT_GREETINGS[context_type]
            # Select a random greeting from the list
            greeting = random.choice(greetings)
        else:
            # Determine greeting type
            greeting_type = "returning" if is_returning else "first_time"
            
            # Get appropriate greeting list based on config
            if agent_config.SHORT_GREETINGS:
                greetings = cls.SHORT_GREETINGS[greeting_type]
            else:
                greetings = cls.STANDARD_GREETINGS[greeting_type]
            
            # Select a random greeting from the list
            greeting = random.choice(greetings)
        
        # Add time-based greeting if provided
        if time_of_day:
            time_greeting = cls.get_time_greeting(time_of_day)
            greeting = f"{time_greeting} {greeting}"
        
        # Format with agent and company name
        return greeting.format(
            agent_name=agent_config.AGENT_NAME,
            company_name=agent_config.COMPANY_NAME
        )
    
    @classmethod
    def get_time_greeting(cls, hour: int) -> str:
        """Get time-appropriate greeting"""
        if hour < 12:
            return "Good morning!"
        elif hour < 17:
            return "Good afternoon!"
        else:
            return "Good evening!"

# Create a singleton instance
greeting_templates = GreetingTemplates
