from typing import List, Optional
from abc import ABC, abstractmethod
import uuid
from .context import Context

class Assistant(ABC):
    def __init__(
        self,
        id: str,
        model: Optional[str] = "",
        name: Optional[str] = None, 
        description: Optional[str] = None, 
        temperature: Optional[float] = 0.7, 
        top_p: Optional[float] = 1.0, 
        instructions: Optional[str] = "",
        tools: Optional[List[str]] = None
    ):
        self.model = model
        self.id = id
        self.object = "assistant"
        self.name = name
        self.description = description
        self.temperature = temperature
        self.top_p = top_p
        self.instructions = instructions
        self.tools = tools or []

        # If name is provided, use it as the ID
        # If no ID and no name is provided, generate a random UUID
        if not id and name:
            self.id = name
        elif not id and not name:
            self.id = str(uuid.uuid4())
        
        if id and not name:
            self.name = id

    @abstractmethod
    async def run(self, context: Context):
        """
        Abstract method that defines the assistant's behavior.
        This should be overridden by subclasses to process the messages and threads.

        :param thread_id: The ID of the thread to run.
        :param messages: The list of messages for the assistant to process.
        :return: A response generated by the assistant.
        """
        pass