import asyncio
import types
import src.modules.prompt.controller as controller_module
from src.modules.prompt.schemas.requests import MultiDocumentVerificationRequest


async def test_business_document_verification(monkeypatch):
    raw = {
        "file_type": "business_documents",
        "file_urls": [
            "https://example.com/business_license.png"
        ],
        "data": {
            "ein": "B2",
            "type": "Stock Broker",
            "location": "LK",
            "business_name": "Business2"
        }
    }
    req = MultiDocumentVerificationRequest.from_raw(raw)

    async def fake_verify_document(file_type, payload, file_url):
        assert file_type == "business_documents"
        return {
            "analysis_results": [
                {"field_name": "ein", "provided_value": payload.get("ein"), "found_in_document": payload.get("ein"), "is_match": True, "confidence": "high"},
                {"field_name": "business_type", "provided_value": payload.get("business_type"), "found_in_document": payload.get("business_type"), "is_match": True, "confidence": "high"},
                {"field_name": "location", "provided_value": payload.get("location"), "found_in_document": payload.get("location"), "is_match": True, "confidence": "high"},
                {"field_name": "business_name", "provided_value": payload.get("business_name"), "found_in_document": payload.get("business_name"), "is_match": True, "confidence": "high"}
            ],
            "overall_match": True,
            "confidence_score": "95%",
            "document_type": "Business License",
            "mismatch_summary": [],
            "is_hazy": False
        }

    monkeypatch.setattr(controller_module.azure_openai_client, "verify_document", fake_verify_document)

    # Fake DB and Request objects
    class _DB: pass
    class _Req: pass
    db = _DB()
    request = _Req()

    resp = await controller_module.verify_multi_documents(db, req, request)
    assert resp.success is True
    assert resp.document_type_detected == "Business License"
    assert resp.overall_match is True
    # Feedback should include all four fields as fully matched
    fully = resp.feedback.get("fully_matched", [])
    for fld in ["ein", "business_type", "location", "business_name"]:
        assert fld in fully
    # Human readable text should exist
    assert resp.feedback_text is not None and len(resp.feedback_text) > 0