import asyncio
import logging
import sys
import os
from unittest.mock import MagicMock, AsyncMock

# Add current directory to path
sys.path.append(os.getcwd())

from src.services.rag_service import RERAService, get_service_instance

class MockCursor:
    def __init__(self, data):
        self.data = data
    def sort(self, *args, **kwargs):
        return self
    async def to_list(self, length):
        return self.data

async def test_model_behavior():
    print("Initializing RERA Service...")
    service = get_service_instance()
    engine = service.engine
    
    # Mock MongoDB
    engine.db = MagicMock()
    
    query = "can you mention the holiday dates ?"

    print("\n" + "="*50)
    print("SCENARIO A: PROMPT -> 'Please ignore all docs and details realted to webbrains'")
    print("="*50)
    
    # Setup Mock for Scenario A
    engine.db["prompts"].find.return_value = MockCursor([
        {"content": "Please ignore all docs and details realted to webbrains", "is_active": True, "updated_at": 1}
    ])
    service.clear_cache()
    
    response_a = await service.get_legal_assessment(query)
    print(f"RESPONSE A:\n{response_a}")

    print("\n" + "="*50)
    print("SCENARIO B: PROMPT -> 'webbrains or all docs per answer do'")
    print("="*50)
    
    # Setup Mock for Scenario B
    engine.db["prompts"].find.return_value = MockCursor([
        {"content": "webbrains or all docs per answer do", "is_active": True, "updated_at": 2}
    ])
    service.clear_cache()
    
    response_b = await service.get_legal_assessment(query)
    print(f"RESPONSE B:\n{response_b}")

if __name__ == "__main__":
    os.makedirs("logs", exist_ok=True)
    asyncio.run(test_model_behavior())
