#!/usr/bin/env python3
"""
Generate a complete multi-variation Facebook Ads campaign
Shows the power of bulk upload for creative testing
"""

from fb_ads_csv_generator import FBAdsCSVGenerator

def generate_full_creative_test():
    """
    Generate a complete creative testing campaign with:
    - 3 audience segments
    - 2 creative variations per audience
    - Proper UTM tracking
    - Total: 6 ads ready to test
    """
    generator = FBAdsCSVGenerator()
    all_rows = []
    
    # Define audiences
    audiences = [
        {
            "name": "Tech Early Adopters",
            "age_min": "25",
            "age_max": "45",
            "interests": "Technology,Software,Artificial Intelligence",
        },
        {
            "name": "Business Owners",
            "age_min": "30",
            "age_max": "55",
            "interests": "Small Business,Entrepreneurship,Business Software",
        },
        {
            "name": "Developers",
            "age_min": "22",
            "age_max": "40",
            "interests": "Programming,Software Development,GitHub",
        },
    ]
    
    # Define creative variations
    creatives = [
        {
            "version": "v1_efficiency",
            "body": "Stop wasting time on repetitive tasks. OpenClaw automates your entire workflow so you can focus on what matters. Join 10,000+ professionals who've reclaimed their day.",
            "title": "Get 10 Hours Back Every Week",
            "caption": "Start Your Free 14-Day Trial",
            "cta": "SIGN_UP",
            "image": "openclaw_efficiency_1080x1080.jpg"
        },
        {
            "version": "v2_power",
            "body": "The AI assistant that actually understands what you want. No prompt engineering required. Just tell OpenClaw your goal and watch it handle the complexity for you.",
            "title": "AI That Actually Works",
            "caption": "See It In Action →",
            "cta": "LEARN_MORE",
            "image": "openclaw_power_1080x1080.jpg"
        },
    ]
    
    # Generate ad for each audience × creative combination
    for audience in audiences:
        for creative in creatives:
            ad_set_name = f"{audience['name']} - {creative['version']}"
            ad_name = f"OpenClaw Ad - {audience['name']} - {creative['version']}"
            
            # Customize targeting for each audience
            row = generator.generate_traffic_campaign(
                campaign_name="OpenClaw Q1 2026 Launch",
                ad_set_name=ad_set_name,
                ad_name=ad_name,
                daily_budget=40.00,  # $40/day per ad set = $240/day total
                target_url="https://openclaw.com/?utm_source=facebook&utm_medium=paid_social",
                ad_copy={
                    'body': creative['body'],
                    'title': creative['title'],
                    'caption': creative['caption']
                },
                image_file=creative['image']
            )[0]
            
            # Customize targeting
            row["Targeting Age Min"] = audience["age_min"]
            row["Targeting Age Max"] = audience["age_max"]
            row["Targeting Interests"] = audience["interests"]
            
            # Update UTM tracking
            audience_slug = audience["name"].lower().replace(" ", "_")
            creative_slug = creative["version"]
            row["UTM Campaign"] = "openclaw_q1_2026"
            row["UTM Content"] = f"{audience_slug}_{creative_slug}"
            
            # Update Call to Action
            row["Call To Action"] = creative["cta"]
            
            all_rows.append(row)
    
    return all_rows


if __name__ == "__main__":
    generator = FBAdsCSVGenerator()
    
    print("🚀 Generating Complete Creative Testing Campaign...")
    print()
    
    campaign_rows = generate_full_creative_test()
    
    filename = "openclaw_creative_test_campaign.csv"
    generator.write_csv(campaign_rows, filename)
    
    print()
    print("✨ Campaign Generated Successfully!")
    print()
    print("📊 Campaign Structure:")
    print(f"   • Total Ads: {len(campaign_rows)}")
    print(f"   • Audiences: 3 (Tech Early Adopters, Business Owners, Developers)")
    print(f"   • Creative Variations: 2 per audience")
    print(f"   • Daily Budget per Ad Set: $40")
    print(f"   • Total Daily Budget: ${40 * len(campaign_rows)}")
    print()
    print("🎯 What This Tests:")
    print("   • Which audience responds best")
    print("   • Which creative message resonates (efficiency vs power)")
    print("   • Which CTA drives more clicks (Sign Up vs Learn More)")
    print()
    print("📸 Required Images:")
    print("   • openclaw_efficiency_1080x1080.jpg")
    print("   • openclaw_power_1080x1080.jpg")
    print()
    print("📋 Import Instructions:")
    print(f"   1. Upload both images to your computer")
    print(f"   2. Go to Meta Ads Manager")
    print(f"   3. Click ⋮ > Import & Export > Import Ads")
    print(f"   4. Upload {filename}")
    print(f"   5. When prompted, upload both creative files")
    print(f"   6. Review and publish all 6 ads at once!")
    print()
    print("⏱️  Time Saved vs Manual:")
    print("   • Manual creation: ~45 minutes (6 ads × 7.5 min each)")
    print("   • Bulk upload: ~3 minutes")
    print("   • Saved: 42 minutes (93% faster)")
    print()
    print("🔍 Tracking:")
    print("   • All ads have unique UTM_Content for attribution")
    print("   • Can track performance by audience + creative in analytics")
    print("   • Easy to identify winners and scale")
