from __future__ import annotations

import json

from app.core.agent.processes.v2.workflows.doc_update_from_feature.doc_rules_pipeline.models import SelectedDocRules
from app.core.agent.processes.v2.workflows.doc_update_from_feature.workflow_runtime.models import PlannedChange


class DocChangePromptBuilder:
    def build(self, item: PlannedChange, rules: SelectedDocRules, domain: str, subdomain: str) -> str:
        payload = {
            "change_request": {
                "op": item.op,
                "path": item.path,
                "doc_type": item.doc_type,
                "doc_id": item.doc_id,
                "title": item.title,
                "domain": domain,
                "sub_domain": subdomain,
                "reason": item.reason,
                "source_refs": item.source_refs,
                "related_docs": item.related_docs,
                "requirement_body": item.requirement_body,
            },
            "doc_rules_context": rules.render_for_prompt(),
        }
        return json.dumps(payload, ensure_ascii=False, indent=2)
