from __future__ import annotations

from ai_orchestrator.orchestrators.base import OrchestratorEngine
from ai_orchestrator.schemas.task_request import TaskRequest
from ai_orchestrator.schemas.task_status import TaskLifecycleStatus
from ai_orchestrator.services.sqlite_store import SQLiteTaskStore


class MicrosoftAgentEngine(OrchestratorEngine):
    def __init__(self, store: SQLiteTaskStore) -> None:
        self.store = store

    async def submit_task(self, task_id: str, request: TaskRequest) -> None:
        task = self.store.get(task_id)
        if task is None:
            return
        task.mark_terminal(
            TaskLifecycleStatus.failed,
            summary="Microsoft Agent Framework support is reserved for the enterprise phase.",
            error_message="Engine not implemented in this phase.",
        )
        self.store.save(task)

    async def get_status(self, task_id: str):
        return self.store.get(task_id)

    async def get_result(self, task_id: str):
        return self.store.get(task_id)

    async def cancel_task(self, task_id: str) -> None:
        task = self.store.get(task_id)
        if task is None or task.status in TaskLifecycleStatus.terminal():
            return
        task.mark_terminal(TaskLifecycleStatus.cancelled, summary="Task cancelled before execution.")
        self.store.save(task)
