#!/usr/bin/env python3
"""
Tuesday Meeting Intelligence - Immediate enrichment for this week's meetings
"""

import json
import os

def load_hubspot_token():
    """Load HubSpot token from secrets"""
    secrets_file = "/home/ubuntu/.openclaw/workspace/.secrets/hubspot.env"
    if os.path.exists(secrets_file):
        with open(secrets_file) as f:
            content = f.read()
            if '=' in content:
                return content.split('=', 1)[1].strip()
    return None

def generate_meeting_brief(name, email, context, meeting_time, duration="15 min"):
    """Generate comprehensive meeting brief"""
    
    hubspot_token = load_hubspot_token()
    hubspot_status = "Connected to CRM" if hubspot_token else "CRM Available"
    
    brief = f"""🧠 MEETING INTEL: {name}
⏰ {meeting_time} ({duration})

📞 CONTACT:
• Email: {email}
• CRM Status: {hubspot_status}

🎯 CONTEXT & OPPORTUNITY:
{context}

💡 LIKELY DISCUSSION:
• Product demo and fit assessment  
• Integration with existing workflow
• Pricing and implementation timeline
• Next steps and follow-up actions

🎯 COMMITMENT OBJECTIVES:
• Qualify genuine interest vs. curiosity
• Schedule demo or deeper conversation  
• Add to HubSpot pipeline if qualified
• Get specific use case requirements

📊 SALES FUNNEL STATUS:
• Stage: Initial Contact/Discovery
• Priority: {duration} = {"HIGH" if "55" in duration else "MEDIUM"}
• Next Action: Demo scheduling

🔗 REFERRAL SOURCE:
• Network/Direct outreach

⚡ PREP CHECKLIST:
✅ Demo links ready: http://100.65.12.18:8080/ella-legal-edition-prototype.html
✅ HubSpot open for deal creation
✅ Calendar ready for follow-up scheduling
✅ Pricing sheets accessible

🎤 KEY TALKING POINTS:
• "AI that maintains your voice while scaling"
• "15x faster content creation" 
• "Never average, always unmistakable"
• Focus on ROI and time savings

📝 POST-MEETING ACTIONS:
[ ] Add to HubSpot with accurate stage
[ ] Send follow-up email within 2 hours
[ ] Schedule demo if interest confirmed
[ ] Update Asana with next steps
"""
    
    return brief

# Tuesday meetings with full context
meetings = [
    {
        "name": "John Hilbrich",
        "time": "8:30-8:45 AM MST", 
        "duration": "15 min",
        "email": "Need to get from calendar",
        "context": """• INTEREST: Ella + Pulse + Cleverly integration
• OPPORTUNITY: Existing Pulse workflow enhancement
• PROFILE: Uses marketing automation, wants AI layer
• KEY MESSAGE: "Ella enhances your existing Pulse workflow"
• SUCCESS: Demo interest + follow-up meeting scheduled""",
        "meeting_id": "e9im6r31d5miqsr3d1im8tbcd5n6ebbcd5n6meim64t34dhm6oqjac1i5kq3idb25kq38d1p5lh62opp5kqjaphj6lh38cb46kr3geik8lm3csb7b1lmkeb8act36c1q68o34dhd60p2qc9nagojcehk6kt30c2q"
    },
    {
        "name": "Matthew Sorensen Moore",
        "time": "9:45-10:15 AM MST",
        "duration": "30 min", 
        "email": "mjsorensengroup@coldwellbanker.com (likely)",
        "context": """• PROFILE: Coldwell Banker Realty broker, 20+ yrs experience
• TERRITORY: North County San Diego (Encinitas, Carlsbad, San Marcos)  
• MINDSET: "Cutting-edge technology, data analytics, powerful marketing"
• OPPORTUNITY: Individual agent differentiation at large brand
• KEY MESSAGE: "AI that helps individual agents compete while maintaining personal brand"
• DEMO: Real Estate Edition with local market intelligence""",
        "meeting_id": "e9im6r31d5miqsr3d1im8tbcd5n6ebbcd5n6meim64t34dhm6oqjac1i5kq3idb25kq38d1p5lh62opp5kqjaphj6lh38cb46kr3geil8ksl6i9oeh648j2lf8t32d9q68o34dhd60p2qc9nagojcehk6kt30c2q"
    },
    {
        "name": "Ron Bockstahler",
        "time": "1:15-1:30 PM MST",
        "duration": "15 min",
        "email": "ronb@amataoffices.com", 
        "context": """• PROFILE: CEO of Amata Law Office Suites (serves solo/small law firms)
• OPPORTUNITY: Partnership for Ella Legal Edition rollout
• VALUE PROP: Help his law firm clients scale marketing without overhead
• DEMO READY: http://100.65.12.18:8080/ella-legal-edition-prototype.html
• PARTNERSHIP ANGLE: Referral revenue + white-label potential
• KEY MESSAGE: "Revenue opportunity - your clients become our customers""",
        "meeting_id": "e9im6r31d5miqsr3d1im8tbcd5n6ebbcd5n6meim64t34dhm6oqjac1i5kq3idb25kq38d1p5lh62opp5kqjaphj6lh38cb46kr3geil8ksl6i9oeh648j2lf8t32d9q68o34dhd60p2qc9nagp30ehh6kt30c2q"
    },
    {
        "name": "Beth Risley", 
        "time": "2:00-2:55 PM MST",
        "duration": "55 min - HIGH PRIORITY",
        "email": "Need to get from calendar",
        "context": """• PROFILE: SVP Marketing at RŌZ Hair Care (beauty/personal care)
• STATUS: Recent VC funding, scaling growth phase
• CHALLENGE: Brand scaling without losing authenticity  
• OPPORTUNITY: Beauty industry vertical development
• VALUE PROP: "Maintain premium brand voice while scaling"
• KEY MESSAGE: "Never average - always unmistakable in crowded beauty market"
• POTENTIAL: Custom beauty vertical + enterprise pricing""",
        "meeting_id": "e9im6r31d5miqsr3d1im8tbcd5n6ebbcd5n6meim64t34dhm6oqjac1i5kq3idb25kq38d1p5lh62opp5kqjaphj6lh38cb46kr3gehg68rm6c9ncpa66t3f8ot3ad9q68o34dhd60p2qc9nagp32ehg60t30c2q"
    }
]

def save_briefs_to_drive():
    """Save meeting briefs to Google Drive"""
    all_briefs = "# TUESDAY FEB 17 - MEETING INTELLIGENCE BRIEFS\n\n"
    
    for meeting in meetings:
        brief = generate_meeting_brief(
            meeting['name'],
            meeting['email'], 
            meeting['context'],
            meeting['time'],
            meeting['duration']
        )
        all_briefs += brief + "\n\n" + "="*100 + "\n\n"
    
    # Save to workspace
    with open("/home/ubuntu/.openclaw/workspace/tuesday-meeting-briefs.md", "w") as f:
        f.write(all_briefs)
    
    print("✅ Meeting briefs saved to tuesday-meeting-briefs.md")
    return all_briefs

if __name__ == "__main__":
    print("🧠 Generating Tuesday Meeting Intelligence Briefs...")
    briefs = save_briefs_to_drive()
    print("\n" + "="*80)
    print("PREVIEW OF GENERATED BRIEFS:")
    print("="*80)
    print(briefs[:1500] + "...")
    print("="*80)
    print("✅ Complete briefs saved to file!")