#!/usr/bin/env python3
"""Morning report generator — runs at 4am AEST"""
import os, sys, json
from pathlib import Path
from datetime import datetime

GENESIS = Path("E:/genesis-system")
SITES = {
    "sunaiva.com": GENESIS / "Sunaiva" / "website" / "index.html",
    "agileadapt.com": GENESIS / "AGILEADAPT" / "website" / "index.html",
    "talkingwebsite.com.au": GENESIS / "RECEPTIONISTAI" / "talkingwebsite" / "index.html",
}

report_lines = [
    "# GENESIS MORNING REPORT",
    f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M AEST')}",
    "",
    "## OPERATION DAYBREAK RESULTS",
    "",
    "## Site Build Status",
]

all_good = True
for site_name, site_path in SITES.items():
    if site_path.exists():
        size = site_path.stat().st_size
        content = site_path.read_text(encoding='utf-8', errors='ignore')
        lines = len(content.split('\n'))
        has_telnyx = 'telnyx-ai-agent' in content
        has_pricing = '497' in content or '697' in content or '997' in content

        status = "READY FOR APPROVAL" if (lines > 200 and has_telnyx) else "NEEDS ATTENTION"
        if "NEEDS ATTENTION" in status:
            all_good = False

        report_lines.extend([
            f"### {site_name}",
            f"- Status: {status}",
            f"- File size: {size:,} bytes ({lines} lines)",
            f"- Telnyx widget: {'YES' if has_telnyx else 'NO'}",
            f"- Pricing section: {'YES' if has_pricing else 'NO'}",
            f"- Path: {site_path}",
            "",
        ])
    else:
        all_good = False
        report_lines.extend([
            f"### {site_name}",
            "- Status: FILE NOT FOUND",
            f"- Expected: {site_path}",
            "",
        ])

report_lines.extend([
    "---",
    f"## Overall: {'ALL SITES READY — APPROVE NOW' if all_good else 'SOME SITES NEED ATTENTION'}",
    "",
    "## Next Actions for Kinan:",
    "1. Review each site at the paths above",
    "2. Deploy to live domains if satisfied",
    "3. Test voice widget on each site",
    "4. Review OVERNIGHT_RESULTS.md for RLM processing summary",
])

report_path = GENESIS / "MORNING_REPORT.md"
report_path.write_text('\n'.join(report_lines), encoding='utf-8')
print(f"Morning report written to {report_path}")
print('\n'.join(report_lines))
