import asyncio
from playwright.async_api import async_playwright

async def verify():
    async with async_playwright() as p:
        # Using default chromium (which might show 'Chrome for Testing')
        browser = await p.chromium.launch(headless=True)
        context = await browser.new_context()
        page = await context.new_page()
        
        results = []
        
        # 1. Verify Memory Site
        try:
            print("Checking Sunaiva AI Memory...")
            await page.goto("https://sunaiva-ai-memory.netlify.app", timeout=30000)
            title = await page.title()
            results.append(f"Memory Site Title: {title}")
            # Check for pricing section
            has_pricing = await page.locator("text=$25").is_visible()
            results.append(f"Memory Site Pricing Visible: {has_pricing}")
        except Exception as e:
            results.append(f"Memory Site Error: {e}")

        # 2. Verify API Health
        try:
            print("Checking Memory API Health...")
            await page.goto("https://api.sunaivadigital.com/memory/api/health", timeout=30000)
            content = await page.content()
            results.append(f"Memory API Health: {'healthy' in content}")
        except Exception as e:
            results.append(f"Memory API Error: {e}")

        # 3. Verify Talking Widget API Health
        try:
            print("Checking Widget API Health...")
            await page.goto("https://api.sunaivadigital.com/health", timeout=30000)
            content = await page.content()
            results.append(f"Widget API Health: {'ok' in content}")
        except Exception as e:
            results.append(f"Widget API Error: {e}")

        # 4. Verify Receptionist AI (IP)
        try:
            print("Checking Receptionist AI (IP)...")
            # This uses self-signed/temp cert on IP, might need to skip ssl
            context_no_ssl = await browser.new_context(ignore_https_errors=True)
            page_no_ssl = await context_no_ssl.new_page()
            await page_no_ssl.goto("https://152.53.201.221", timeout=30000)
            title = await page_no_ssl.title()
            results.append(f"Receptionist AI Title: {title}")
        except Exception as e:
            results.append(f"Receptionist AI Error: {e}")

        await browser.close()
        
        print("\n=== VERIFICATION RESULTS ===")
        for r in results:
            print(r)

if __name__ == "__main__":
    asyncio.run(verify())
