from pydantic import BaseModel
from datetime import datetime
from .apps.app import App
from .apps.clock import Clock
from .apps.task_manager import TaskManager
from .apps.constitution import Constitution
from autogen import AssistantAgent
from .apps.object_store import ObjectStore
from .apps.budget import BudgetApp
from .apps.job_board import JobBoard

class SystemConfig(BaseModel):
    clock_start: datetime
    data_path: str

class System:
    config: SystemConfig
    clock: Clock
    apps: dict[str, App]
    task_manager: TaskManager
    constitution: Constitution
    
    def __init__(self, config=SystemConfig | dict):
        if isinstance(config, dict):
            config = SystemConfig(**config)
        
        self.config = config
        
        self.clock = Clock(config.clock_start)
        self.store = ObjectStore(self.clock, config.data_path)
        self.task_manager = TaskManager(self.clock, self.store)
        self.constitution = Constitution(self.clock, self.store)
        self.apps = {
            "task_manager": self.task_manager,
            "constitution": self.constitution,
            "budget": BudgetApp(self.clock, self.store),
            "job_board": JobBoard(self.clock, self.store)
        }
        
    def get_executor(self):
        return AssistantAgent(
            name="Executor",
            description="Use this agent to execute calls to tools",
            system_message="You ONLY execute tools calls and returns the responses.",
        )