# Copyright (c) 2025 Patrick Motsch
# All rights reserved.
# modeBase.py
# Abstract base class for workflow modes

from abc import ABC, abstractmethod
import logging
from typing import List, Dict, Any
from modules.datamodels.datamodelChat import TaskStep, TaskContext, TaskResult, ActionItem
from modules.datamodels.datamodelChat import ChatWorkflow
from modules.workflows.processing.core.taskPlanner import TaskPlanner
from modules.workflows.processing.core.actionExecutor import ActionExecutor
from modules.workflows.processing.core.messageCreator import MessageCreator
from modules.workflows.processing.core.validator import WorkflowValidator

logger = logging.getLogger(__name__)

class BaseMode(ABC):
    """Abstract base class for workflow execution modes"""
    
    def __init__(self, services):
        self.services = services
        self.taskPlanner = TaskPlanner(services)
        self.actionExecutor = ActionExecutor(services)
        self.messageCreator = MessageCreator(services)
        self.validator = WorkflowValidator(services)
    
    
    @abstractmethod
    async def executeTask(self, taskStep: TaskStep, workflow: ChatWorkflow, context: TaskContext) -> TaskResult:
        """Execute a task step - must be implemented by concrete modes"""
        pass
    
    @abstractmethod
    async def generateActionItems(self, taskStep: TaskStep, workflow: ChatWorkflow, 
                                 previousResults: List = None, enhancedContext: TaskContext = None) -> List[ActionItem]:
        """Generate actions for a task step - must be implemented by concrete modes"""
        pass
    
    async def generateTaskPlan(self, userInput: str, workflow: ChatWorkflow):
        """Generate task plan - common to all modes"""
        return await self.taskPlanner.generateTaskPlan(userInput, workflow)
    
    async def createTaskPlanMessage(self, taskPlan, workflow: ChatWorkflow):
        """Create task plan message - common to all modes"""
        return await self.messageCreator.createTaskPlanMessage(taskPlan, workflow)
