<?php
if ( ! defined( 'ABSPATH' ) ) exit;

/**
 * VMO Turnkey Business Blueprints
 * 
 * Complete business configurations that VMO can build and manage autonomously.
 * Each blueprint includes: website structure, required pages, systems, automations,
 * email templates, legal documents, daily tasks, and success metrics.
 * 
 * @package VMO_AI_Website_Builder
 * @since 8.2.0
 */

if (!defined('ABSPATH')) {
    exit;
}

class VMO_Turnkey_Business_Blueprints {
    
    private static $instance = null;
    
    public static function get_instance() {
        if (self::$instance === null) {
            self::$instance = new self();
        }
        return self::$instance;
    }
    
    /**
     * Get all available turnkey business types
     */
    public function get_available_business_types() {
        return array(
            'dropshipping' => 'Dropshipping Store',
            'export_agency' => 'Export Agency',
            'va_agency' => 'Virtual Assistant Agency',
            'print_on_demand' => 'Print-on-Demand Store',
            'content_agency' => 'Content/SEO Agency',
            'local_service' => 'Local Service Business',
            'affiliate_marketing' => 'Affiliate Marketing',
            'digital_products' => 'Digital Products Store',
            'consulting' => 'Consulting/Coaching Business',
            'saas_reseller' => 'SaaS Reseller/Consultant',
            'social_media_agency' => 'Social Media Management Agency',
            'bookkeeping' => 'Virtual Bookkeeping Service',
        );
    }
    
    /**
     * Get complete blueprint for a business type
     */
    public function get_business_blueprint($business_type) {
        $blueprints = $this->get_all_blueprints();
        return isset($blueprints[$business_type]) ? $blueprints[$business_type] : null;
    }
    
    /**
     * Get all turnkey business blueprints with complete configurations
     */
    public function get_all_blueprints() {
        return array(
            
            // ============================================================
            // DROPSHIPPING STORE
            // ============================================================
            'dropshipping' => array(
                'name' => 'Dropshipping Store',
                'description' => 'Sell products online without holding inventory. Suppliers ship directly to customers.',
                'difficulty' => 'beginner',
                'startup_cost' => array('min' => 100, 'max' => 500, 'currency' => 'USD'),
                'time_to_profit' => '2-4 months',
                'income_potential' => array(
                    'month_1' => array('min' => 0, 'max' => 500),
                    'month_3' => array('min' => 500, 'max' => 2000),
                    'month_6' => array('min' => 1000, 'max' => 5000),
                    'year_1' => array('min' => 2000, 'max' => 10000),
                ),
                'hours_per_week' => array('min' => 10, 'max' => 30),
                'location_requirements' => 'anywhere',
                
                // Website Structure
                'website' => array(
                    'type' => 'ecommerce',
                    'pages' => array(
                        'home' => array(
                            'name' => 'Home',
                            'sections' => array('hero', 'featured_products', 'categories', 'testimonials', 'newsletter'),
                            'purpose' => 'Showcase best products and build trust'
                        ),
                        'shop' => array(
                            'name' => 'Shop',
                            'sections' => array('product_grid', 'filters', 'search'),
                            'purpose' => 'Browse and purchase products'
                        ),
                        'product' => array(
                            'name' => 'Product Page',
                            'sections' => array('product_images', 'description', 'price', 'add_to_cart', 'reviews', 'related'),
                            'purpose' => 'Detailed product view with purchase option'
                        ),
                        'cart' => array(
                            'name' => 'Shopping Cart',
                            'sections' => array('cart_items', 'subtotal', 'checkout_button'),
                            'purpose' => 'Review items before checkout'
                        ),
                        'checkout' => array(
                            'name' => 'Checkout',
                            'sections' => array('shipping_form', 'payment', 'order_summary'),
                            'purpose' => 'Complete purchase'
                        ),
                        'about' => array(
                            'name' => 'About Us',
                            'sections' => array('story', 'mission', 'team'),
                            'purpose' => 'Build trust and brand connection'
                        ),
                        'contact' => array(
                            'name' => 'Contact',
                            'sections' => array('contact_form', 'faq', 'support_hours'),
                            'purpose' => 'Customer support'
                        ),
                        'shipping' => array(
                            'name' => 'Shipping & Returns',
                            'sections' => array('shipping_info', 'return_policy', 'tracking'),
                            'purpose' => 'Set customer expectations'
                        ),
                    ),
                    'features' => array('product_catalog', 'shopping_cart', 'secure_checkout', 'order_tracking', 'customer_accounts', 'reviews'),
                    'integrations' => array('stripe', 'paypal', 'shipping_calculator'),
                ),
                
                // Email System
                'email_roles' => array(
                    'info' => array('purpose' => 'General inquiries', 'template' => 'info@{domain}'),
                    'support' => array('purpose' => 'Customer support', 'template' => 'support@{domain}'),
                    'orders' => array('purpose' => 'Order notifications', 'template' => 'orders@{domain}'),
                    'marketing' => array('purpose' => 'Promotions', 'template' => 'deals@{domain}'),
                ),
                
                // Automations
                'automations' => array(
                    'order_confirmation' => 'Send confirmation email when order placed',
                    'shipping_notification' => 'Notify customer when order ships',
                    'review_request' => 'Request review 7 days after delivery',
                    'abandoned_cart' => 'Remind customers of abandoned carts after 1 hour',
                    'welcome_series' => '3-email welcome sequence for new subscribers',
                ),
                
                // Legal Documents
                'legal_documents' => array('privacy_policy', 'terms_of_service', 'refund_policy', 'shipping_policy', 'cookie_policy'),
                
                // Daily Tasks for User
                'daily_tasks' => array(
                    'week_1' => array(
                        'day_1' => array('Set up store theme and branding', 'Connect payment processor'),
                        'day_2' => array('Research 10 potential products', 'Analyze competitor pricing'),
                        'day_3' => array('Add first 5 products to store', 'Write compelling descriptions'),
                        'day_4' => array('Set up shipping rates', 'Configure order notifications'),
                        'day_5' => array('Create social media accounts', 'Design first 3 social posts'),
                        'day_6' => array('Launch store soft opening', 'Share with friends/family for feedback'),
                        'day_7' => array('Analyze feedback', 'Make adjustments'),
                    ),
                    'week_2' => array(
                        'daily' => array('Add 2-3 new products', 'Post on social media', 'Respond to inquiries'),
                    ),
                    'week_3_4' => array(
                        'daily' => array('Run first paid ads ($5-10/day)', 'Analyze ad performance', 'Fulfill orders', 'Customer service'),
                    ),
                    'ongoing' => array(
                        'daily' => array('Check orders', 'Respond to messages', 'Post content'),
                        'weekly' => array('Analyze sales data', 'Add new products', 'Optimize ads'),
                        'monthly' => array('Review profit margins', 'Test new suppliers', 'Plan promotions'),
                    ),
                ),
                
                // Success Metrics
                'kpis' => array(
                    'conversion_rate' => array('target' => '2-3%', 'description' => 'Visitors who purchase'),
                    'average_order_value' => array('target' => '$30-50', 'description' => 'Average cart value'),
                    'customer_acquisition_cost' => array('target' => '<$15', 'description' => 'Cost to get a customer'),
                    'profit_margin' => array('target' => '20-40%', 'description' => 'After all costs'),
                ),
                
                // Learning Resources
                'education' => array(
                    'how_it_works' => 'You list products from suppliers. When customer orders, you purchase from supplier who ships directly to them. You keep the profit margin.',
                    'key_terms' => array(
                        'Supplier' => 'Company that holds inventory and ships products',
                        'Margin' => 'Difference between your price and supplier cost',
                        'AliExpress' => 'Popular supplier platform for dropshipping',
                        'Oberlo/DSers' => 'Apps that automate product importing',
                    ),
                    'common_mistakes' => array(
                        'Choosing oversaturated products',
                        'Setting margins too low',
                        'Poor customer service',
                        'Not testing products before selling',
                    ),
                ),
            ),
            
            // ============================================================
            // EXPORT AGENCY
            // ============================================================
            'export_agency' => array(
                'name' => 'Export Agency',
                'description' => 'Connect local suppliers with international buyers. Earn commissions on trade deals.',
                'difficulty' => 'intermediate',
                'startup_cost' => array('min' => 200, 'max' => 1000, 'currency' => 'USD'),
                'time_to_profit' => '3-6 months',
                'income_potential' => array(
                    'month_1' => array('min' => 0, 'max' => 0),
                    'month_3' => array('min' => 500, 'max' => 2000),
                    'month_6' => array('min' => 2000, 'max' => 5000),
                    'year_1' => array('min' => 5000, 'max' => 20000),
                ),
                'hours_per_week' => array('min' => 15, 'max' => 40),
                'location_requirements' => array('best_for' => array('Nigeria', 'Ghana', 'Kenya', 'India', 'Vietnam', 'Colombia', 'Mexico')),
                
                // Website Structure
                'website' => array(
                    'type' => 'b2b_services',
                    'pages' => array(
                        'home' => array(
                            'name' => 'Home',
                            'sections' => array('hero', 'services', 'product_categories', 'why_us', 'testimonials', 'cta'),
                            'purpose' => 'Attract international buyers'
                        ),
                        'products' => array(
                            'name' => 'Product Catalog',
                            'sections' => array('category_grid', 'product_listings', 'specifications', 'moq'),
                            'purpose' => 'Showcase available export products'
                        ),
                        'suppliers' => array(
                            'name' => 'For Suppliers',
                            'sections' => array('benefits', 'how_it_works', 'application_form'),
                            'purpose' => 'Recruit local suppliers'
                        ),
                        'how_it_works' => array(
                            'name' => 'How It Works',
                            'sections' => array('process_steps', 'shipping_info', 'payment_terms'),
                            'purpose' => 'Explain the export process'
                        ),
                        'about' => array(
                            'name' => 'About Us',
                            'sections' => array('company_story', 'team', 'certifications', 'partnerships'),
                            'purpose' => 'Build credibility'
                        ),
                        'contact' => array(
                            'name' => 'Contact / RFQ',
                            'sections' => array('inquiry_form', 'office_locations', 'response_time'),
                            'purpose' => 'Generate buyer inquiries'
                        ),
                    ),
                    'features' => array('product_catalog', 'rfq_system', 'supplier_portal', 'document_generation'),
                    'integrations' => array('whatsapp_business', 'email_automation', 'crm'),
                ),
                
                // Email System
                'email_roles' => array(
                    'info' => array('purpose' => 'General inquiries', 'template' => 'info@{domain}'),
                    'trade' => array('purpose' => 'Trade inquiries', 'template' => 'trade@{domain}'),
                    'suppliers' => array('purpose' => 'Supplier communications', 'template' => 'suppliers@{domain}'),
                    'logistics' => array('purpose' => 'Shipping coordination', 'template' => 'logistics@{domain}'),
                ),
                
                // Automations
                'automations' => array(
                    'inquiry_response' => 'Auto-reply to buyer inquiries with catalog',
                    'supplier_onboarding' => 'Welcome sequence for new suppliers',
                    'quote_followup' => 'Follow up on quotes after 3 days',
                    'shipment_updates' => 'Notify buyers of shipment status',
                ),
                
                // Legal Documents
                'legal_documents' => array('privacy_policy', 'terms_of_service', 'trade_terms', 'supplier_agreement', 'buyer_agreement'),
                
                // Daily Tasks
                'daily_tasks' => array(
                    'week_1' => array(
                        'day_1_3' => array('Research 20 local suppliers', 'Document products and prices', 'Take product photos'),
                        'day_4_5' => array('List products on website', 'Create product specifications'),
                        'day_6_7' => array('Join B2B platforms (Alibaba, TradeKey)', 'Create seller profiles'),
                    ),
                    'week_2' => array(
                        'daily' => array('Reach out to 5 potential buyers', 'Respond to inquiries', 'Negotiate with suppliers'),
                    ),
                    'ongoing' => array(
                        'daily' => array('Check messages from buyers', 'Coordinate with suppliers', 'Update product listings'),
                        'weekly' => array('Add new products', 'Follow up on pending quotes', 'Build new supplier relationships'),
                        'monthly' => array('Review margins', 'Negotiate better supplier rates', 'Attend trade events'),
                    ),
                ),
                
                // Success Metrics
                'kpis' => array(
                    'inquiry_to_deal' => array('target' => '10-20%', 'description' => 'Inquiries that become orders'),
                    'average_deal_value' => array('target' => '$5,000-50,000', 'description' => 'Per shipment'),
                    'commission_rate' => array('target' => '5%', 'description' => 'Your fixed recurring share of each plan sale'),
                    'repeat_buyer_rate' => array('target' => '40%+', 'description' => 'Buyers who order again'),
                ),
                
                // Learning Resources
                'education' => array(
                    'how_it_works' => 'You find local products (agricultural, crafts, textiles, etc.) and market them to international buyers. When a buyer places an order, you coordinate between them and the supplier, handle documentation, and earn a commission.',
                    'key_terms' => array(
                        'FOB' => 'Free On Board - price includes delivery to port',
                        'CIF' => 'Cost, Insurance, Freight - includes shipping to destination',
                        'MOQ' => 'Minimum Order Quantity',
                        'LC' => 'Letter of Credit - bank-guaranteed payment',
                        'Proforma Invoice' => 'Quote document before actual invoice',
                    ),
                    'common_mistakes' => array(
                        'Not verifying supplier reliability',
                        'Underquoting shipping costs',
                        'Poor documentation',
                        'Not getting payment upfront',
                    ),
                ),
            ),
            
            // ============================================================
            // VIRTUAL ASSISTANT AGENCY
            // ============================================================
            'va_agency' => array(
                'name' => 'Virtual Assistant Agency',
                'description' => 'Hire VAs from your region and provide services to businesses in higher-paying markets.',
                'difficulty' => 'intermediate',
                'startup_cost' => array('min' => 50, 'max' => 200, 'currency' => 'USD'),
                'time_to_profit' => '1-3 months',
                'income_potential' => array(
                    'month_1' => array('min' => 200, 'max' => 500),
                    'month_3' => array('min' => 1000, 'max' => 3000),
                    'month_6' => array('min' => 2000, 'max' => 5000),
                    'year_1' => array('min' => 5000, 'max' => 15000),
                ),
                'hours_per_week' => array('min' => 20, 'max' => 40),
                'location_requirements' => array('best_for' => array('Philippines', 'India', 'Nigeria', 'Kenya', 'Pakistan', 'South Africa')),
                
                // Website Structure
                'website' => array(
                    'type' => 'service_agency',
                    'pages' => array(
                        'home' => array(
                            'name' => 'Home',
                            'sections' => array('hero', 'services', 'benefits', 'how_it_works', 'testimonials', 'cta'),
                            'purpose' => 'Attract business clients'
                        ),
                        'services' => array(
                            'name' => 'Services',
                            'sections' => array('admin_support', 'customer_service', 'social_media', 'data_entry', 'bookkeeping', 'pricing'),
                            'purpose' => 'Detail service offerings'
                        ),
                        'pricing' => array(
                            'name' => 'Pricing',
                            'sections' => array('packages', 'hourly_rates', 'custom_plans', 'comparison_table'),
                            'purpose' => 'Transparent pricing'
                        ),
                        'about' => array(
                            'name' => 'About Us',
                            'sections' => array('story', 'team', 'training_process', 'quality_assurance'),
                            'purpose' => 'Build trust'
                        ),
                        'hire' => array(
                            'name' => 'Hire a VA',
                            'sections' => array('requirements_form', 'va_matching', 'onboarding_process'),
                            'purpose' => 'Client intake'
                        ),
                        'careers' => array(
                            'name' => 'Join Our Team',
                            'sections' => array('benefits', 'requirements', 'application_form'),
                            'purpose' => 'Recruit VAs'
                        ),
                        'contact' => array(
                            'name' => 'Contact',
                            'sections' => array('contact_form', 'calendly', 'support'),
                            'purpose' => 'Start conversations'
                        ),
                    ),
                    'features' => array('booking_system', 'client_portal', 'time_tracking', 'invoicing'),
                    'integrations' => array('calendly', 'stripe', 'slack', 'time_doctor', 'hubspot'),
                ),
                
                // Email System
                'email_roles' => array(
                    'info' => array('purpose' => 'General inquiries', 'template' => 'info@{domain}'),
                    'hire' => array('purpose' => 'Client inquiries', 'template' => 'hire@{domain}'),
                    'careers' => array('purpose' => 'VA applications', 'template' => 'careers@{domain}'),
                    'support' => array('purpose' => 'Client support', 'template' => 'support@{domain}'),
                ),
                
                // Automations
                'automations' => array(
                    'client_inquiry' => 'Auto-reply with service brochure',
                    'va_application' => 'Send screening questionnaire',
                    'onboarding_sequence' => 'Welcome emails for new clients',
                    'weekly_reports' => 'Automated work summary to clients',
                    'invoice_reminders' => 'Payment reminders before due date',
                ),
                
                // Legal Documents
                'legal_documents' => array('privacy_policy', 'terms_of_service', 'client_agreement', 'va_contractor_agreement', 'nda_template'),
                
                // Daily Tasks
                'daily_tasks' => array(
                    'week_1' => array(
                        'day_1_2' => array('Define service offerings', 'Set pricing structure'),
                        'day_3_4' => array('Post job ads for VAs', 'Screen applications'),
                        'day_5_7' => array('Interview candidates', 'Create training materials'),
                    ),
                    'week_2' => array(
                        'daily' => array('Reach out to 10 potential clients', 'Follow up on leads', 'Train VAs'),
                    ),
                    'ongoing' => array(
                        'daily' => array('Client communication', 'VA check-ins', 'Quality reviews'),
                        'weekly' => array('Client reports', 'VA team meetings', 'Lead generation'),
                        'monthly' => array('Performance reviews', 'Process improvements', 'Client retention calls'),
                    ),
                ),
                
                // Success Metrics
                'kpis' => array(
                    'client_retention' => array('target' => '80%+', 'description' => 'Clients who stay monthly'),
                    'va_utilization' => array('target' => '75%+', 'description' => 'Billable hours per VA'),
                    'margin_per_va' => array('target' => '$5-15/hour', 'description' => 'Your profit per VA hour'),
                    'client_satisfaction' => array('target' => '4.5+/5', 'description' => 'Client rating'),
                ),
                
                // Learning Resources
                'education' => array(
                    'how_it_works' => 'You hire VAs in your region for $3-8/hour and provide their services to US/UK/AU businesses for $15-35/hour. You manage the client relationship, handle quality control, and keep the difference.',
                    'key_terms' => array(
                        'Retainer' => 'Monthly package of hours',
                        'Billable Hours' => 'Time you can charge clients for',
                        'SOP' => 'Standard Operating Procedure - documented process',
                        'White Label' => 'Your VAs work under your brand name',
                    ),
                    'common_mistakes' => array(
                        'Overpromising to clients',
                        'Not having backup VAs',
                        'Poor communication processes',
                        'Not documenting procedures',
                    ),
                ),
            ),
            
            // ============================================================
            // PRINT-ON-DEMAND
            // ============================================================
            'print_on_demand' => array(
                'name' => 'Print-on-Demand Store',
                'description' => 'Design products (shirts, mugs, etc.) and platforms print/ship when ordered.',
                'difficulty' => 'beginner',
                'startup_cost' => array('min' => 0, 'max' => 100, 'currency' => 'USD'),
                'time_to_profit' => '1-3 months',
                'income_potential' => array(
                    'month_1' => array('min' => 0, 'max' => 200),
                    'month_3' => array('min' => 200, 'max' => 800),
                    'month_6' => array('min' => 500, 'max' => 2000),
                    'year_1' => array('min' => 1000, 'max' => 5000),
                ),
                'hours_per_week' => array('min' => 5, 'max' => 20),
                'location_requirements' => 'anywhere',
                
                // Website Structure
                'website' => array(
                    'type' => 'ecommerce',
                    'pages' => array(
                        'home' => array(
                            'name' => 'Home',
                            'sections' => array('hero', 'featured_designs', 'categories', 'bestsellers'),
                            'purpose' => 'Showcase unique designs'
                        ),
                        'shop' => array(
                            'name' => 'Shop',
                            'sections' => array('design_gallery', 'product_types', 'filters'),
                            'purpose' => 'Browse and buy products'
                        ),
                        'about' => array(
                            'name' => 'About',
                            'sections' => array('designer_story', 'mission'),
                            'purpose' => 'Connect with customers'
                        ),
                        'faq' => array(
                            'name' => 'FAQ',
                            'sections' => array('shipping', 'sizing', 'returns', 'custom_orders'),
                            'purpose' => 'Answer common questions'
                        ),
                    ),
                    'features' => array('product_mockups', 'size_guides', 'design_preview', 'secure_checkout'),
                    'integrations' => array('printful', 'printify', 'stripe', 'social_sharing'),
                ),
                
                // Email System
                'email_roles' => array(
                    'hello' => array('purpose' => 'General contact', 'template' => 'hello@{domain}'),
                    'orders' => array('purpose' => 'Order updates', 'template' => 'orders@{domain}'),
                ),
                
                // Automations
                'automations' => array(
                    'order_confirmation' => 'Confirm order and explain timeline',
                    'production_update' => 'Notify when production starts',
                    'shipping_notification' => 'Send tracking info',
                    'review_request' => 'Ask for review after delivery',
                ),
                
                // Legal Documents
                'legal_documents' => array('privacy_policy', 'terms_of_service', 'return_policy'),
                
                // Daily Tasks
                'daily_tasks' => array(
                    'week_1' => array(
                        'day_1_3' => array('Connect to Printful/Printify', 'Choose product types', 'Learn design tools'),
                        'day_4_7' => array('Create 10-15 designs', 'Apply to products', 'Set pricing'),
                    ),
                    'week_2' => array(
                        'daily' => array('Create 2-3 new designs', 'Post on social media', 'Research trends'),
                    ),
                    'ongoing' => array(
                        'daily' => array('Create 1+ design', 'Social media posts', 'Customer service'),
                        'weekly' => array('Analyze bestsellers', 'Follow design trends', 'Optimize listings'),
                    ),
                ),
                
                // Success Metrics
                'kpis' => array(
                    'designs_live' => array('target' => '50+', 'description' => 'Active designs'),
                    'profit_per_sale' => array('target' => '$5-15', 'description' => 'After print/ship costs'),
                    'bestseller_ratio' => array('target' => '10-20%', 'description' => 'Designs that sell well'),
                ),
                
                // Learning Resources
                'education' => array(
                    'how_it_works' => 'You create designs and apply them to products (shirts, hoodies, mugs, etc.). When someone orders, the print company produces and ships it. You never touch inventory.',
                    'key_terms' => array(
                        'Mockup' => 'Product preview image with your design',
                        'Base Cost' => 'What the printer charges you',
                        'Niche' => 'Specific audience for your designs',
                    ),
                    'common_mistakes' => array(
                        'Generic designs that don\'t stand out',
                        'Not researching trends',
                        'Too few designs',
                        'Not marketing actively',
                    ),
                ),
            ),
            
            // ============================================================
            // CONTENT/SEO AGENCY
            // ============================================================
            'content_agency' => array(
                'name' => 'Content & SEO Agency',
                'description' => 'Write content for businesses. Charge per article or monthly retainers.',
                'difficulty' => 'beginner',
                'startup_cost' => array('min' => 50, 'max' => 200, 'currency' => 'USD'),
                'time_to_profit' => '2-4 weeks',
                'income_potential' => array(
                    'month_1' => array('min' => 300, 'max' => 1000),
                    'month_3' => array('min' => 1000, 'max' => 3000),
                    'month_6' => array('min' => 2000, 'max' => 6000),
                    'year_1' => array('min' => 4000, 'max' => 15000),
                ),
                'hours_per_week' => array('min' => 10, 'max' => 40),
                'location_requirements' => 'anywhere',
                
                // Website Structure
                'website' => array(
                    'type' => 'service_portfolio',
                    'pages' => array(
                        'home' => array(
                            'name' => 'Home',
                            'sections' => array('hero', 'services', 'sample_work', 'testimonials', 'cta'),
                            'purpose' => 'Attract clients'
                        ),
                        'services' => array(
                            'name' => 'Services',
                            'sections' => array('blog_writing', 'seo_content', 'copywriting', 'editing', 'pricing'),
                            'purpose' => 'Detail offerings'
                        ),
                        'portfolio' => array(
                            'name' => 'Portfolio',
                            'sections' => array('sample_articles', 'case_studies', 'industries'),
                            'purpose' => 'Show expertise'
                        ),
                        'about' => array(
                            'name' => 'About',
                            'sections' => array('writer_bio', 'process', 'values'),
                            'purpose' => 'Build connection'
                        ),
                        'contact' => array(
                            'name' => 'Contact',
                            'sections' => array('inquiry_form', 'calendly', 'pricing_inquiry'),
                            'purpose' => 'Start projects'
                        ),
                    ),
                    'features' => array('portfolio_gallery', 'contact_form', 'scheduling'),
                    'integrations' => array('calendly', 'stripe', 'notion'),
                ),
                
                // Email System
                'email_roles' => array(
                    'hello' => array('purpose' => 'General contact', 'template' => 'hello@{domain}'),
                    'projects' => array('purpose' => 'Project communication', 'template' => 'projects@{domain}'),
                ),
                
                // Automations
                'automations' => array(
                    'inquiry_response' => 'Send welcome packet and questionnaire',
                    'onboarding' => 'New client welcome sequence',
                    'invoice_automation' => 'Monthly invoice generation',
                ),
                
                // Legal Documents
                'legal_documents' => array('privacy_policy', 'terms_of_service', 'client_agreement', 'content_license'),
                
                // Daily Tasks
                'daily_tasks' => array(
                    'week_1' => array(
                        'day_1_3' => array('Create 5 portfolio samples', 'Define service packages'),
                        'day_4_7' => array('Set up profiles on Upwork, LinkedIn', 'Apply to 20 jobs', 'Network in groups'),
                    ),
                    'week_2' => array(
                        'daily' => array('Apply to 5-10 opportunities', 'Write and deliver content', 'Follow up on proposals'),
                    ),
                    'ongoing' => array(
                        'daily' => array('Client work', 'Prospecting', 'Skill development'),
                        'weekly' => array('New portfolio pieces', 'Client follow-ups', 'Marketing'),
                    ),
                ),
                
                // Success Metrics
                'kpis' => array(
                    'retainer_clients' => array('target' => '3-5', 'description' => 'Monthly recurring clients'),
                    'rate_per_word' => array('target' => '$0.10-0.30', 'description' => 'Writing rate'),
                    'client_retention' => array('target' => '70%+', 'description' => 'Clients who continue'),
                ),
                
                // Learning Resources
                'education' => array(
                    'how_it_works' => 'Businesses need content for blogs, websites, and marketing. You write it for them and charge per piece or monthly. Good content helps them rank on Google and attract customers.',
                    'key_terms' => array(
                        'SEO' => 'Search Engine Optimization - writing to rank on Google',
                        'Retainer' => 'Monthly contract for ongoing work',
                        'Content Brief' => 'Instructions for what to write',
                    ),
                    'common_mistakes' => array(
                        'Underpricing your work',
                        'No samples to show',
                        'Not specializing in a niche',
                        'Inconsistent quality',
                    ),
                ),
            ),
            
            // ============================================================
            // LOCAL SERVICE BUSINESS
            // ============================================================
            'local_service' => array(
                'name' => 'Local Service Business',
                'description' => 'Be the manager - hire contractors to do cleaning, lawn care, handyman work, etc.',
                'difficulty' => 'intermediate',
                'startup_cost' => array('min' => 500, 'max' => 2000, 'currency' => 'USD'),
                'time_to_profit' => '1-2 months',
                'income_potential' => array(
                    'month_1' => array('min' => 500, 'max' => 2000),
                    'month_3' => array('min' => 2000, 'max' => 5000),
                    'month_6' => array('min' => 4000, 'max' => 10000),
                    'year_1' => array('min' => 6000, 'max' => 20000),
                ),
                'hours_per_week' => array('min' => 15, 'max' => 40),
                'location_requirements' => array('best_for' => array('USA', 'UK', 'Canada', 'Australia')),
                
                // Website Structure
                'website' => array(
                    'type' => 'local_service',
                    'pages' => array(
                        'home' => array(
                            'name' => 'Home',
                            'sections' => array('hero', 'services', 'service_areas', 'testimonials', 'cta', 'trust_badges'),
                            'purpose' => 'Attract local customers'
                        ),
                        'services' => array(
                            'name' => 'Services',
                            'sections' => array('service_list', 'pricing', 'before_after'),
                            'purpose' => 'Detail all offerings'
                        ),
                        'booking' => array(
                            'name' => 'Book Online',
                            'sections' => array('service_selector', 'date_picker', 'contact_info', 'payment'),
                            'purpose' => 'Online booking'
                        ),
                        'about' => array(
                            'name' => 'About Us',
                            'sections' => array('story', 'team', 'insurance_info', 'guarantees'),
                            'purpose' => 'Build trust'
                        ),
                        'areas' => array(
                            'name' => 'Service Areas',
                            'sections' => array('map', 'city_pages', 'zip_codes'),
                            'purpose' => 'Local SEO'
                        ),
                        'contact' => array(
                            'name' => 'Contact',
                            'sections' => array('contact_form', 'phone', 'hours'),
                            'purpose' => 'Easy contact'
                        ),
                    ),
                    'features' => array('online_booking', 'quote_calculator', 'customer_portal', 'review_display'),
                    'integrations' => array('google_calendar', 'stripe', 'quickbooks', 'google_my_business'),
                ),
                
                // Email System
                'email_roles' => array(
                    'info' => array('purpose' => 'General inquiries', 'template' => 'info@{domain}'),
                    'bookings' => array('purpose' => 'Appointment notifications', 'template' => 'bookings@{domain}'),
                    'billing' => array('purpose' => 'Invoices', 'template' => 'billing@{domain}'),
                ),
                
                // Automations
                'automations' => array(
                    'booking_confirmation' => 'Confirm appointment details',
                    'reminder_24h' => 'Reminder 24 hours before',
                    'followup_review' => 'Request review after service',
                    'requote_reminder' => 'Follow up on unbooked quotes',
                ),
                
                // Legal Documents
                'legal_documents' => array('privacy_policy', 'terms_of_service', 'service_agreement', 'liability_waiver'),
                
                // Daily Tasks
                'daily_tasks' => array(
                    'week_1' => array(
                        'day_1_2' => array('Get business license', 'Get insurance quote'),
                        'day_3_4' => array('Post job ads for contractors', 'Screen applicants'),
                        'day_5_7' => array('Create pricing sheet', 'Set up booking system'),
                    ),
                    'week_2' => array(
                        'daily' => array('Google My Business setup', 'Leaflet distribution', 'Nextdoor/Facebook marketing'),
                    ),
                    'ongoing' => array(
                        'daily' => array('Answer calls/messages', 'Schedule jobs', 'Quality check'),
                        'weekly' => array('Pay contractors', 'Marketing', 'Customer follow-up'),
                        'monthly' => array('Review finances', 'Contractor review', 'Expand service area'),
                    ),
                ),
                
                // Success Metrics
                'kpis' => array(
                    'jobs_per_week' => array('target' => '10-20', 'description' => 'Completed jobs'),
                    'average_job_value' => array('target' => '$75-200', 'description' => 'Per job revenue'),
                    'profit_margin' => array('target' => '30-50%', 'description' => 'After paying contractors'),
                    'repeat_customers' => array('target' => '40%+', 'description' => 'Customers who return'),
                ),
                
                // Learning Resources
                'education' => array(
                    'how_it_works' => 'You\'re the business manager. You get customers, schedule jobs, and hire contractors to do the work. You charge customers $X and pay contractors $Y, keeping the difference.',
                    'key_terms' => array(
                        '1099 Contractor' => 'Independent worker (not employee)',
                        'General Liability Insurance' => 'Protection if something goes wrong',
                        'CRM' => 'Customer Relationship Management system',
                    ),
                    'common_mistakes' => array(
                        'Not having insurance',
                        'Unreliable contractors',
                        'Underpricing services',
                        'No systems for scheduling',
                    ),
                ),
            ),
            
            // ============================================================
            // AFFILIATE MARKETING
            // ============================================================
            'affiliate_marketing' => array(
                'name' => 'Affiliate Marketing',
                'description' => 'Promote other companies\' products and earn commission on sales.',
                'difficulty' => 'beginner',
                'startup_cost' => array('min' => 0, 'max' => 200, 'currency' => 'USD'),
                'time_to_profit' => '3-6 months',
                'income_potential' => array(
                    'month_1' => array('min' => 0, 'max' => 100),
                    'month_3' => array('min' => 100, 'max' => 500),
                    'month_6' => array('min' => 500, 'max' => 2000),
                    'year_1' => array('min' => 1000, 'max' => 10000),
                ),
                'hours_per_week' => array('min' => 10, 'max' => 30),
                'location_requirements' => 'anywhere',
                
                // Website Structure
                'website' => array(
                    'type' => 'content_blog',
                    'pages' => array(
                        'home' => array(
                            'name' => 'Home',
                            'sections' => array('hero', 'featured_reviews', 'categories', 'latest_posts'),
                            'purpose' => 'Hub for content'
                        ),
                        'blog' => array(
                            'name' => 'Blog',
                            'sections' => array('article_grid', 'categories', 'search'),
                            'purpose' => 'SEO content'
                        ),
                        'reviews' => array(
                            'name' => 'Reviews',
                            'sections' => array('product_reviews', 'comparison_tables', 'ratings'),
                            'purpose' => 'Affiliate conversions'
                        ),
                        'best_of' => array(
                            'name' => 'Best [Niche]',
                            'sections' => array('top_picks', 'comparison', 'buying_guide'),
                            'purpose' => 'High-intent pages'
                        ),
                        'about' => array(
                            'name' => 'About',
                            'sections' => array('author_bio', 'mission', 'affiliate_disclosure'),
                            'purpose' => 'Trust and compliance'
                        ),
                    ),
                    'features' => array('affiliate_links', 'comparison_tables', 'email_capture', 'product_boxes'),
                    'integrations' => array('amazon_associates', 'shareasale', 'mailchimp', 'google_analytics'),
                ),
                
                // Email System
                'email_roles' => array(
                    'hello' => array('purpose' => 'Contact', 'template' => 'hello@{domain}'),
                ),
                
                // Automations
                'automations' => array(
                    'welcome_sequence' => '5-email value sequence for subscribers',
                    'product_recommendations' => 'Personalized product suggestions',
                ),
                
                // Legal Documents
                'legal_documents' => array('privacy_policy', 'terms_of_service', 'affiliate_disclosure', 'cookie_policy'),
                
                // Daily Tasks
                'daily_tasks' => array(
                    'week_1' => array(
                        'day_1_3' => array('Choose niche', 'Research affiliate programs', 'Set up website'),
                        'day_4_7' => array('Write 5 pillar articles', 'Join affiliate networks'),
                    ),
                    'week_2_4' => array(
                        'daily' => array('Publish 1 article', 'Keyword research', 'Build backlinks'),
                    ),
                    'ongoing' => array(
                        'daily' => array('Content creation', 'SEO optimization', 'Social sharing'),
                        'weekly' => array('Analytics review', 'Link building', 'New program applications'),
                        'monthly' => array('Performance analysis', 'Content updates', 'Strategy refinement'),
                    ),
                ),
                
                // Success Metrics
                'kpis' => array(
                    'monthly_traffic' => array('target' => '10K+ visitors', 'description' => 'Organic traffic'),
                    'conversion_rate' => array('target' => '2-5%', 'description' => 'Click to purchase'),
                    'earnings_per_click' => array('target' => '$0.10-1.00', 'description' => 'Revenue per click'),
                    'content_pieces' => array('target' => '50+', 'description' => 'Published articles'),
                ),
                
                // Learning Resources
                'education' => array(
                    'how_it_works' => 'You create content that helps people make buying decisions. When they click your affiliate link and purchase, you earn a commission (typically 3-50% depending on the product).',
                    'key_terms' => array(
                        'Affiliate Link' => 'Special URL that tracks your referrals',
                        'Commission' => 'Percentage of sale you earn',
                        'Cookie Duration' => 'How long after click you get credit',
                        'EPC' => 'Earnings Per Click',
                    ),
                    'common_mistakes' => array(
                        'Choosing saturated niches',
                        'Not disclosing affiliate relationships',
                        'Thin/low-quality content',
                        'Expecting quick results',
                    ),
                ),
            ),
            
            // ============================================================
            // DIGITAL PRODUCTS
            // ============================================================
            'digital_products' => array(
                'name' => 'Digital Products Store',
                'description' => 'Sell courses, templates, ebooks, or other digital downloads.',
                'difficulty' => 'intermediate',
                'startup_cost' => array('min' => 50, 'max' => 500, 'currency' => 'USD'),
                'time_to_profit' => '2-4 months',
                'income_potential' => array(
                    'month_1' => array('min' => 0, 'max' => 500),
                    'month_3' => array('min' => 500, 'max' => 2000),
                    'month_6' => array('min' => 1000, 'max' => 5000),
                    'year_1' => array('min' => 3000, 'max' => 20000),
                ),
                'hours_per_week' => array('min' => 10, 'max' => 30),
                'location_requirements' => 'anywhere',
                
                // Website Structure
                'website' => array(
                    'type' => 'digital_store',
                    'pages' => array(
                        'home' => array(
                            'name' => 'Home',
                            'sections' => array('hero', 'featured_products', 'testimonials', 'about_creator'),
                            'purpose' => 'Showcase products'
                        ),
                        'products' => array(
                            'name' => 'Products',
                            'sections' => array('product_grid', 'categories', 'bundles'),
                            'purpose' => 'Browse offerings'
                        ),
                        'product_page' => array(
                            'name' => 'Product Detail',
                            'sections' => array('sales_video', 'description', 'features', 'preview', 'pricing', 'faq', 'testimonials'),
                            'purpose' => 'Convert visitors'
                        ),
                        'checkout' => array(
                            'name' => 'Checkout',
                            'sections' => array('order_summary', 'payment', 'guarantee'),
                            'purpose' => 'Complete purchase'
                        ),
                        'thank_you' => array(
                            'name' => 'Thank You',
                            'sections' => array('confirmation', 'download_access', 'next_steps', 'upsell'),
                            'purpose' => 'Deliver and upsell'
                        ),
                        'about' => array(
                            'name' => 'About',
                            'sections' => array('creator_story', 'credentials', 'mission'),
                            'purpose' => 'Build authority'
                        ),
                    ),
                    'features' => array('digital_delivery', 'course_platform', 'member_area', 'affiliate_program'),
                    'integrations' => array('stripe', 'gumroad', 'teachable', 'convertkit'),
                ),
                
                // Email System
                'email_roles' => array(
                    'hello' => array('purpose' => 'Contact', 'template' => 'hello@{domain}'),
                    'support' => array('purpose' => 'Customer support', 'template' => 'support@{domain}'),
                ),
                
                // Automations
                'automations' => array(
                    'welcome_buyer' => 'Delivery email with access',
                    'onboarding_sequence' => 'Help customer use product',
                    'review_request' => 'Ask for testimonial after 7 days',
                    'abandoned_cart' => 'Recover incomplete purchases',
                ),
                
                // Legal Documents
                'legal_documents' => array('privacy_policy', 'terms_of_service', 'refund_policy', 'license_agreement'),
                
                // Daily Tasks
                'daily_tasks' => array(
                    'week_1_4' => array(
                        'focus' => array('Create your first product', 'Outline content', 'Record/write content', 'Design materials'),
                    ),
                    'week_5_8' => array(
                        'focus' => array('Build sales page', 'Set up delivery', 'Create marketing content', 'Soft launch'),
                    ),
                    'ongoing' => array(
                        'daily' => array('Customer support', 'Marketing content', 'Engage audience'),
                        'weekly' => array('Analyze sales', 'Update products', 'New content creation'),
                        'monthly' => array('New product planning', 'Email campaigns', 'Partnership outreach'),
                    ),
                ),
                
                // Success Metrics
                'kpis' => array(
                    'conversion_rate' => array('target' => '2-5%', 'description' => 'Visitors who buy'),
                    'average_order_value' => array('target' => '$27-97', 'description' => 'Typical product price'),
                    'refund_rate' => array('target' => '<5%', 'description' => 'Customers who refund'),
                    'email_list_size' => array('target' => '1000+', 'description' => 'Subscriber count'),
                ),
                
                // Learning Resources
                'education' => array(
                    'how_it_works' => 'You create something once (course, template, ebook) and sell it unlimited times. After initial creation, it\'s mostly passive income. No inventory, no shipping.',
                    'key_terms' => array(
                        'Lead Magnet' => 'Free item to grow email list',
                        'Sales Page' => 'Long-form page that sells your product',
                        'Upsell' => 'Additional offer after purchase',
                        'Funnel' => 'Journey from visitor to customer',
                    ),
                    'common_mistakes' => array(
                        'Building before validating demand',
                        'Overcomplicating first product',
                        'Not building email list',
                        'Underpricing',
                    ),
                ),
            ),
        );
    }
    
    /**
     * Get blueprint suitable for AI context (condensed version)
     */
    public function get_blueprint_for_ai_context($business_type) {
        $blueprint = $this->get_business_blueprint($business_type);
        if (!$blueprint) {
            return '';
        }
        
        $context = "=== TURNKEY BUSINESS BLUEPRINT: {$blueprint['name']} ===\n\n";
        $context .= "Description: {$blueprint['description']}\n";
        $context .= "Difficulty: {$blueprint['difficulty']}\n";
        $context .= "Startup Cost: \${$blueprint['startup_cost']['min']}-\${$blueprint['startup_cost']['max']}\n";
        $context .= "Time to Profit: {$blueprint['time_to_profit']}\n";
        $context .= "Hours/Week: {$blueprint['hours_per_week']['min']}-{$blueprint['hours_per_week']['max']}\n\n";
        
        $context .= "INCOME TRAJECTORY:\n";
        foreach ($blueprint['income_potential'] as $period => $range) {
            $period_label = str_replace('_', ' ', ucfirst($period));
            $context .= "- {$period_label}: \${$range['min']}-\${$range['max']}/month\n";
        }
        
        $context .= "\nWEBSITE PAGES TO BUILD:\n";
        foreach ($blueprint['website']['pages'] as $page_key => $page) {
            $context .= "- {$page['name']}: {$page['purpose']}\n";
        }
        
        $context .= "\nEMAIL ADDRESSES TO CREATE:\n";
        foreach ($blueprint['email_roles'] as $role => $config) {
            $context .= "- {$config['template']}: {$config['purpose']}\n";
        }
        
        $context .= "\nAUTOMATIONS TO SET UP:\n";
        foreach ($blueprint['automations'] as $name => $desc) {
            $context .= "- " . str_replace('_', ' ', ucfirst($name)) . ": {$desc}\n";
        }
        
        $context .= "\nLEGAL DOCUMENTS NEEDED:\n";
        $context .= "- " . implode(', ', array_map(function($doc) {
            return ucwords(str_replace('_', ' ', (string) $doc));
        }, $blueprint['legal_documents'])) . "\n";
        
        $context .= "\nHOW IT WORKS:\n{$blueprint['education']['how_it_works']}\n";
        
        $context .= "\nKEY TERMS TO TEACH USER:\n";
        foreach ($blueprint['education']['key_terms'] as $term => $definition) {
            $context .= "- {$term}: {$definition}\n";
        }
        
        $context .= "\nCOMMON MISTAKES TO AVOID:\n";
        foreach ($blueprint['education']['common_mistakes'] as $mistake) {
            $context .= "- {$mistake}\n";
        }
        
        return $context;
    }
    
    /**
     * Get daily tasks for a business type formatted for dashboard
     */
    public function get_daily_tasks_for_dashboard($business_type, $current_week = 1) {
        $blueprint = $this->get_business_blueprint($business_type);
        if (!$blueprint || !isset($blueprint['daily_tasks'])) {
            return array();
        }
        
        return $blueprint['daily_tasks'];
    }
    
    /**
     * Get KPIs for dashboard tracking
     */
    public function get_kpis($business_type) {
        $blueprint = $this->get_business_blueprint($business_type);
        if (!$blueprint || !isset($blueprint['kpis'])) {
            return array();
        }
        
        return $blueprint['kpis'];
    }
    
    /**
     * Recommend business types based on user profile
     */
    public function recommend_businesses($user_profile) {
        $location = strtolower($user_profile['location'] ?? '');
        $budget = $user_profile['budget'] ?? 500;
        $hours = $user_profile['hours_per_week'] ?? 20;
        $income_goal = $user_profile['income_goal'] ?? 2000;
        $experience = $user_profile['experience'] ?? 'beginner';
        
        $recommendations = array();
        $blueprints = $this->get_all_blueprints();
        
        foreach ($blueprints as $type => $blueprint) {
            $score = 0;
            
            // Budget match
            if ($budget >= $blueprint['startup_cost']['min']) {
                $score += 20;
            }
            
            // Time match
            if ($hours >= $blueprint['hours_per_week']['min']) {
                $score += 20;
            }
            
            // Income goal match (check if year 1 potential meets goal)
            if ($blueprint['income_potential']['year_1']['max'] >= $income_goal) {
                $score += 25;
            }
            
            // Difficulty match
            if ($experience === 'beginner' && $blueprint['difficulty'] === 'beginner') {
                $score += 20;
            } elseif ($experience === 'intermediate' || $experience === 'advanced') {
                $score += 15;
            }
            
            // Location match
            if ($blueprint['location_requirements'] === 'anywhere') {
                $score += 15;
            } elseif (isset($blueprint['location_requirements']['best_for'])) {
                foreach ($blueprint['location_requirements']['best_for'] as $best_location) {
                    if (stripos($location, strtolower($best_location)) !== false) {
                        $score += 25; // Bonus for location match
                        break;
                    }
                }
            }
            
            $recommendations[$type] = array(
                'blueprint' => $blueprint,
                'score' => $score,
                'match_reasons' => array()
            );
        }
        
        // Sort by score descending
        uasort($recommendations, function($a, $b) {
            return $b['score'] - $a['score'];
        });
        
        // Return top 5
        return array_slice($recommendations, 0, 5, true);
    }
}

// Initialize
VMO_Turnkey_Business_Blueprints::get_instance();
