#!/usr/bin/env python3
"""
Sunaiva Deployment Verification Script
Checks health, auth pages, and SSL status of the live deployment.
"""

import sys
import requests
from datetime import datetime

API_URL = "https://api.sunaivadigital.com"
WIDGET_URL = "https://widget.sunaivadigital.com"

def check_endpoint(url, description, expected_status=200, is_html=False):
    print(f"Checking {description} ({url})...", end=" ")
    try:
        response = requests.get(url, timeout=10)
        if response.status_code == expected_status:
            if is_html and "<!DOCTYPE html>" in response.text:
                print("✅ PASS")
                return True
            elif not is_html:
                print("✅ PASS")
                return True
            else:
                print(f"❌ FAIL (Content mismatch)")
                return False
        else:
            print(f"❌ FAIL (Status {response.status_code})")
            return False
    except Exception as e:
        print(f"❌ FAIL ({e})")
        return False

def main():
    print(f"=== Sunaiva Deployment Verification {datetime.now()} ===\\n")
    
    success = True
    
    # 1. API Health
    if not check_endpoint(f"{API_URL}/health", "API Health"): success = False
    
    # 2. Auth Pages
    if not check_endpoint(f"{API_URL}/login", "Login Page", is_html=True): success = False
    if not check_endpoint(f"{API_URL}/signup", "Signup Page", is_html=True): success = False
    
    # 3. Widget JS (Expect failure if DNS not propagated)
    print(f"\\nChecking Widget CDN ({WIDGET_URL}/v1/widget.js)...")
    try:
        requests.get(f"{WIDGET_URL}/v1/widget.js", timeout=5)
        print("✅ PASS (DNS Propagated)")
    except Exception as e:
        print(f"⚠️  WARN (DNS likely not propagated yet): {e}")
        
    print(f"\\n{'='*40}")
    if success:
        print("🚀 DEPLOYMENT SUCCESSFUL")
        print("Backend is live and serving content.")
    else:
        print("⚠️  DEPLOYMENT ISSUES DETECTED")
        
if __name__ == "__main__":
    main()
