#!/usr/bin/env python3
"""
Daily Meeting Brief System - Creates individual day files + weekly highlights
"""

import json
from datetime import datetime, timedelta

def get_business_dates(start_date, days=5):
    """Get next 5 business days (Mon-Fri) starting from date"""
    business_dates = []
    current_date = start_date
    
    while len(business_dates) < days:
        if current_date.weekday() < 5:  # Monday = 0, Friday = 4
            business_dates.append(current_date)
        current_date += timedelta(days=1)
    
    return business_dates

def create_daily_brief(date, meetings=[]):
    """Create brief for a specific day"""
    
    day_name = date.strftime("%A %B %d, %Y")
    
    # Sample meetings data - in real system would pull from calendar/CRM
    if date.strftime("%Y-%m-%d") == "2026-02-17":  # Tuesday
        meetings = [
            {
                "time": "8:30-8:45 AM",
                "name": "John Hilbrich", 
                "context": "Ella + Pulse integration. 15-min focused demo.",
                "priority": "Medium",
                "prep": "Demo links ready, integration talking points"
            },
            {
                "time": "9:45-10:15 AM", 
                "name": "Matthew Sorensen Moore",
                "context": "Real estate broker, 20+ years. Tech-forward, wants AI edge.",
                "priority": "Medium", 
                "prep": "Real Estate Edition demo, local market features"
            },
            {
                "time": "1:15-1:30 PM",
                "name": "Ron Bockstahler",
                "context": "CEO Amata Law Suites. Partnership for Legal Edition.",
                "priority": "High",
                "prep": "Legal Edition demo: http://100.65.12.18:8080/ella-legal-edition-prototype.html"
            },
            {
                "time": "2:00-2:55 PM",
                "name": "Beth Risley",
                "context": "SVP Marketing RŌZ Hair Care. 55-min = TOP PRIORITY.",
                "priority": "CRITICAL",
                "prep": "Deep company research, beauty vertical discussion"
            }
        ]
    
    brief = f"""# {day_name} - Meeting Brief

## MEETINGS TODAY

"""
    
    if not meetings:
        brief += "No external meetings scheduled.\n\n"
    else:
        for meeting in meetings:
            brief += f"""### {meeting['time']} - {meeting['name']} ({meeting['priority']})

**CONTEXT:** {meeting['context']}

**PREP STATUS:** {meeting['prep']}

**OBJECTIVES:**
- Qualify interest and fit
- Schedule follow-up or demo
- Add to pipeline if qualified

---

"""
    
    brief += f"""## PREP CHECKLIST

**Before Meetings:**
- [ ] Review latest email threads with each attendee
- [ ] Confirm demo links are working
- [ ] Update HubSpot with meeting outcomes
- [ ] Prepare follow-up emails

**Demo Links Ready:**
- Legal Edition: http://100.65.12.18:8080/ella-legal-edition-prototype.html
- SMB Presentation: https://www.beautiful.ai/player/-OeceotWcAyr91gOsE8v

**Post-Meeting Actions:**
- [ ] Update HubSpot pipeline stages
- [ ] Send follow-up emails within 2 hours
- [ ] Schedule demos if interest confirmed
- [ ] Update Asana with next steps

## CALENDAR NOTES

All meeting intelligence has been added to private calendar descriptions.
Check calendar for specific talking points and background research.
"""
    
    return brief

def create_weekly_highlights():
    """Create weekly highlights brief showing work needed for next 5 days"""
    
    today = datetime.now()
    business_dates = get_business_dates(today, 5)
    
    highlights = f"""# Weekly Highlights - Support Work Needed

**Updated:** {today.strftime("%A %B %d, %Y at %I:%M %p")}

**Coverage Period:** {business_dates[0].strftime("%b %d")} - {business_dates[-1].strftime("%b %d")}

## HIGH-PRIORITY WORK

### Immediate (Next 2 Days)
- **Tuesday Meetings Prep** - 4 external meetings need final preparation
  - Beth Risley research (RŌZ Hair Care) - TOP PRIORITY 
  - Legal Edition demo testing
  - Real Estate Edition customization
  - Pulse integration talking points

### This Week
- **Metronomics Reading** - Chapters 4-7 due Feb 19 (CEO Vision & Alignment)
- **RE Edition Playbook** - Standardization overdue since Feb 13
- **Enterprise Deal Follow-ups** - Multiple prospects in pipeline
- **Board Presentation** - Q1 metrics preparation

## SUPPORT OFFERS

**Research I Can Do:**
- RŌZ Hair Care deep dive (company, competitors, positioning)
- Beauty industry vertical analysis
- Real estate market intelligence (North County San Diego)
- Legal services market sizing and opportunities

**Documents I Can Create:**
- Metronomics summary with key insights
- Demo customization scripts for each prospect
- Industry-specific talking points
- Competitive analysis briefs

**Systems I Can Set Up:**
- Beauty industry Ella environment testing
- Legal Edition demo optimization
- Real Estate Edition local market examples
- Follow-up email templates

## CALENDAR BLOCKING NEEDED

**Monday Feb 16:**
- Morning: 2 hours meeting prep and demo testing
- Afternoon: 3 hours deep research and customization

**Tuesday Feb 17:**
- Buffer time between meetings for notes and follow-up
- Post-meeting: 1 hour for pipeline updates and email drafts

**Wednesday-Friday:**
- Deep work blocks for Metronomics reading
- RE Edition playbook completion
- Board presentation preparation

## BOTTLENECK ALERTS

**Potential Issues:**
- Tuesday meeting density (4 external meetings in one day)
- Beth Risley meeting length (55 minutes) may run over
- Metronomics reading competes with meeting prep time
- Multiple overdue items creating backlog

**Recommendations:**
- Start beauty industry research over weekend
- Test all demo environments Monday AM
- Block time for reading before it becomes urgent
- Prioritize highest-value prospects (Beth, Ron partnership)
"""
    
    return highlights

def create_all_daily_briefs():
    """Create briefs for next 5 business days"""
    
    today = datetime.now()
    
    # Special logic: If Friday, include Monday in the 5-day window
    if today.weekday() == 4:  # Friday
        # Start from Monday instead of today
        start_date = today + timedelta(days=3)  # Next Monday
    else:
        start_date = today
    
    business_dates = get_business_dates(start_date, 5)
    
    created_files = []
    
    for date in business_dates:
        filename = f"daily-meetings-{date.strftime('%Y-%m-%d')}.md"
        filepath = f"/home/ubuntu/.openclaw/workspace/{filename}"
        
        brief = create_daily_brief(date)
        
        with open(filepath, "w") as f:
            f.write(brief)
        
        created_files.append(filename)
        print(f"Created: {filename}")
    
    # Create weekly highlights
    highlights = create_weekly_highlights()
    highlights_path = "/home/ubuntu/.openclaw/workspace/weekly-highlights-brief.md"
    
    with open(highlights_path, "w") as f:
        f.write(highlights)
    
    created_files.append("weekly-highlights-brief.md")
    print("Created: weekly-highlights-brief.md")
    
    return created_files

if __name__ == "__main__":
    print("Creating Daily Meeting Brief System...")
    files = create_all_daily_briefs()
    print(f"\nCreated {len(files)} files:")
    for f in files:
        print(f"  - {f}")
    print("\nDaily brief system ready!")