from __future__ import annotations

from app.core.agent.processes.v2.workflows.doc_explain_api_exposed.steps.build_api_exposed_evidence_step import (
    BuildApiExposedEvidenceStep,
)
from app.core.agent.processes.v2.workflows.doc_explain_api_exposed.steps.fetch_rag_rows_step import FetchRagRowsStep
from app.core.agent.processes.v2.workflows.doc_explain_api_exposed.steps.finalize_api_exposed_answer_step import (
    FinalizeApiExposedAnswerStep,
)
from app.core.agent.processes.v2.workflows.doc_explain_api_exposed.steps.require_rag_session_step import (
    RequireRagSessionStep,
)
from app.core.agent.processes.v2.workflows.doc_explain_api_exposed.steps.resolve_retrieval_plan_step import (
    ResolveRetrievalPlanStep,
)
from app.core.agent.processes.v2.workflows.doc_explain_api_exposed.steps.retrieval.api_endpoint_collector import (
    ApiEndpointCollector,
)
from app.core.agent.processes.v2.workflows.doc_explain_api_exposed.workflow_runtime.buffered_graph import (
    DocExplainApiExposedWorkflowGraph,
)
from app.core.agent.processes.v2.workflows.doc_explain_api_exposed.workflow_runtime.context import (
    DocExplainApiExposedContext,
)
from app.core.agent.utils.process_v2.plan_resolver import RetrievalPlanResolver
from app.core.agent.utils.process_v2.rag_retrieval import V2RagRetrievalAdapter


class DocExplainApiExposedGraph(DocExplainApiExposedWorkflowGraph[DocExplainApiExposedContext]):
    def __init__(
        self,
        policy_resolver: RetrievalPlanResolver,
        rag_adapter: V2RagRetrievalAdapter,
    ) -> None:
        super().__init__(
            workflow_id="v2.docs_explain.api_exposed",
            source="workflow.v2.api_exposed",
            steps=[
                RequireRagSessionStep(
                    missing_message="Для процесса v2 нужна активная RAG-сессия проекта с проиндексированной документацией."
                ),
                ResolveRetrievalPlanStep(policy_resolver),
                FetchRagRowsStep(rag_adapter),
                BuildApiExposedEvidenceStep(ApiEndpointCollector()),
                FinalizeApiExposedAnswerStep(),
            ],
        )

