<?php

namespace Database\Seeders;

use App\Models\EmailTemplate;
use Illuminate\Database\Seeder;

class EmailTemplateSeeder extends Seeder
{
    public function run(): void
    {
        $templates = [
            [
                'title'            => 'SaaS Welcome & Onboarding Series',
                'email_subject'    => 'Welcome to {{company}}! Let\'s get started ',
                'email_pre_header' => 'We\'re excited to have you on board. Here is how to get started.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'Welcome to {{company}}!', 'align' => 'center', 'bgColor' => '#ffffff', 'textColor' => '#111827'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>We are thrilled to welcome you to our community! Whether you\'re here to grow your business, streamline your workflow, or connect with your audience, we\'ve got you covered.<br><br>Here are 3 quick steps to get started:<br>1. Complete your account profile<br>2. Connect your first integration<br>3. Launch your first campaign', 'textColor' => '#374151'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Explore Your Dashboard', 'url' => '#', 'align' => 'center', 'btnColor' => '#4285f4', 'textColor' => '#ffffff'],
                    ['id' => 'blk-4', 'type' => 'divider', 'lineColor' => '#e5e7eb'],
                    ['id' => 'blk-5', 'type' => 'text', 'content' => 'Got questions? Reply directly to this email or check out our Help Center.', 'textColor' => '#6b7280'],
                ],
            ],
            [
                'title'            => 'Flash Sale & Limited Time Offer',
                'email_subject'    => '48 Hours Only: 30% OFF Everything!',
                'email_pre_header' => 'Exclusive discount inside. Don\'t miss out on our biggest sale.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'SPECIAL FLASH SALE', 'align' => 'center', 'bgColor' => '#111827', 'textColor' => '#ffffff'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>For the next 48 hours only, enjoy <strong>30% OFF</strong> our entire catalog. Use promo code <strong>FLASH30</strong> at checkout.', 'textColor' => '#374151'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Shop the Sale Now', 'url' => '#', 'align' => 'center', 'btnColor' => '#ea4335', 'textColor' => '#ffffff'],
                    ['id' => 'blk-4', 'type' => 'divider', 'lineColor' => '#e5e7eb'],
                ],
            ],
            [
                'title'            => 'Monthly Insights & Product Updates',
                'email_subject'    => 'Monthly Digest: Product updates & industry trends',
                'email_pre_header' => 'Here\'s a recap of top news and feature releases from this month.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'Monthly Product Roundup', 'align' => 'center', 'bgColor' => '#f9fafb', 'textColor' => '#111827'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Welcome to our monthly digest! Here are the latest feature updates and industry insights curated just for you.', 'textColor' => '#374151'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Read Full Release Notes', 'url' => '#', 'align' => 'center', 'btnColor' => '#34a853', 'textColor' => '#ffffff'],
                ],
            ],
            [
                'title'            => 'Abandoned Cart Recovery & Offer',
                'email_subject'    => 'You left items in your shopping cart!',
                'email_pre_header' => 'Your saved items are waiting for you. Complete your order today.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'Did you forget something?', 'align' => 'center', 'bgColor' => '#ffffff', 'textColor' => '#111827'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>We noticed you left some items in your shopping cart. Don\'t worry, we\'ve saved them for you! Use code <strong>CART10</strong> for 10% off.', 'textColor' => '#374151'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Return to Cart & Checkout', 'url' => '#', 'align' => 'center', 'btnColor' => '#2563eb', 'textColor' => '#ffffff'],
                ],
            ],
            [
                'title'            => 'Customer Satisfaction & NPS Survey',
                'email_subject'    => 'We\'d love your feedback, {{first_name}}!',
                'email_pre_header' => 'Tell us about your experience in 2 quick minutes.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'How did we do?', 'align' => 'center', 'bgColor' => '#ffffff', 'textColor' => '#111827'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>Your opinion matters immensely to us. Could you take 2 minutes to let us know how we can serve you better?', 'textColor' => '#374151'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Take Quick 2-Min Survey', 'url' => '#', 'align' => 'center', 'btnColor' => '#f9ab00', 'textColor' => '#ffffff'],
                ],
            ],
            [
                'title'            => 'Customer Re-engagement & Winback',
                'email_subject'    => 'We miss you, {{first_name}}! Here is $15 off 🎁',
                'email_pre_header' => 'It\'s been a while! Come back and see what\'s new.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'We Miss Having You Around!', 'align' => 'center', 'bgColor' => '#ffffff', 'textColor' => '#111827'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>It\'s been a while since your last visit. Here is a special gift: <strong>$15 OFF</strong> your next order with coupon code <strong>WELCOMEBACK</strong>.', 'textColor' => '#374151'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Claim My $15 Gift', 'url' => '#', 'align' => 'center', 'btnColor' => '#4285f4', 'textColor' => '#ffffff'],
                ],
            ],
            [
                'title'            => 'Live Webinar & Masterclass Invitation',
                'email_subject'    => 'You\'re Invited: Live Growth Masterclass',
                'email_pre_header' => 'Reserve your seat for our exclusive live webinar.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'LIVE WEBINAR INVITATION', 'align' => 'center', 'bgColor' => '#2563eb', 'textColor' => '#ffffff'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Join industry leaders as we discuss proven strategies, automation hacks, and customer retention techniques.<br><br><strong>Date:</strong> Thursday, July 30th<br><strong>Time:</strong> 2:00 PM EST', 'textColor' => '#374151'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Reserve My Seat Now', 'url' => '#', 'align' => 'center', 'btnColor' => '#10b981', 'textColor' => '#ffffff'],
                ],
            ],
            [
                'title'            => 'New Feature & Product Launch',
                'email_subject'    => 'Introducing our biggest feature release of 2026',
                'email_pre_header' => 'Discover how our new tools will save you hours every week.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'INTRODUCING SMART AUTOMATIONS', 'align' => 'center', 'bgColor' => '#0f172a', 'textColor' => '#38bdf8'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>We are thrilled to announce our brand new Smart Automation Suite! Built from the ground up to automate complex workflows in minutes.', 'textColor' => '#334155'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Try New Feature Now', 'url' => '#', 'align' => 'center', 'btnColor' => '#0284c7', 'textColor' => '#ffffff'],
                ],
            ],
            [
                'title'            => 'Black Friday / Cyber Monday Deals',
                'email_subject'    => 'Black Friday: Up to 50% OFF All Plans!',
                'email_pre_header' => 'Our biggest sale of the year is officially live.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'BLACK FRIDAY MEGA SALE', 'align' => 'center', 'bgColor' => '#000000', 'textColor' => '#facc15'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>Don\'t wait! Upgrade your account today and lock in <strong>50% OFF</strong> for life.', 'textColor' => '#1e293b'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Unlock 50% Discount', 'url' => '#', 'align' => 'center', 'btnColor' => '#e11d48', 'textColor' => '#ffffff'],
                ],
            ],
            [
                'title'            => 'VIP Loyalty & Reward Program',
                'email_subject'    => 'You\'re invited to join our VIP Rewards Club',
                'email_pre_header' => 'Earn points, unlock perks, and get exclusive rewards.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'WELCOME TO VIP REWARDS', 'align' => 'center', 'bgColor' => '#581c87', 'textColor' => '#fde047'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>As one of our most valued customers, you have been invited to join our VIP Loyalty Program. Earn points on every purchase and redeem them for cash discounts.', 'textColor' => '#334155'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Join VIP Rewards', 'url' => '#', 'align' => 'center', 'btnColor' => '#7e22ce', 'textColor' => '#ffffff'],
                ],
            ],
            [
                'title'            => 'Order Confirmation & Receipt',
                'email_subject'    => 'Receipt for your order #{{order_id}}',
                'email_pre_header' => 'Thank you for your order! Here are your receipt details.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'Thank You For Your Order!', 'align' => 'center', 'bgColor' => '#f8fafc', 'textColor' => '#0f172a'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>We\'ve received your order and are getting it ready. Here is a summary of your order details.', 'textColor' => '#334155'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Track Your Order', 'url' => '#', 'align' => 'center', 'btnColor' => '#2563eb', 'textColor' => '#ffffff'],
                ],
            ],
            [
                'title'            => 'Subscription Renewal & Plan Upgrade',
                'email_subject'    => 'Your {{company}} subscription is renewing soon',
                'email_pre_header' => 'Review your plan details or switch to annual to save 20%.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'Upcoming Subscription Renewal', 'align' => 'center', 'bgColor' => '#ffffff', 'textColor' => '#1e293b'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>Your plan will automatically renew next week. Upgrade to our annual plan today to save 20% on your subscription.', 'textColor' => '#334155'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Switch to Annual & Save', 'url' => '#', 'align' => 'center', 'btnColor' => '#16a34a', 'textColor' => '#ffffff'],
                ],
            ],
            [
                'title'            => 'Customer Case Study & Success Story',
                'email_subject'    => 'How Acme Corp boosted revenue by 300%',
                'email_pre_header' => 'Learn the exact strategies used to scale customer acquisition.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'CUSTOMER SUCCESS STORY', 'align' => 'center', 'bgColor' => '#f1f5f9', 'textColor' => '#0f172a'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>Discover how Acme Corp leveraged CRMfic automated workflows to achieve 3x customer retention in just 90 days.', 'textColor' => '#334155'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Read Full Case Study', 'url' => '#', 'align' => 'center', 'btnColor' => '#2563eb', 'textColor' => '#ffffff'],
                ],
            ],
            [
                'title'            => 'Season\'s Greetings & Year in Review',
                'email_subject'    => 'Season\'s Greetings from all of us at {{company}}',
                'email_pre_header' => 'Thank you for a wonderful year! Here is a recap of what we accomplished together.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'HAPPY HOLIDAYS!', 'align' => 'center', 'bgColor' => '#991b1b', 'textColor' => '#ffffff'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>As the year comes to a close, we want to express our deepest gratitude for your continued partnership. Wishing you joy and success in the new year!', 'textColor' => '#334155'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'View Holiday Specials', 'url' => '#', 'align' => 'center', 'btnColor' => '#dc2626', 'textColor' => '#ffffff'],
                ],
            ],
            [
                'title'            => 'Trial Expiration Warning & Special Offer',
                'email_subject'    => '⚠️ Your free trial expires in 3 days',
                'email_pre_header' => 'Upgrade now to keep your data and unlock full access.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'YOUR TRIAL IS ENDING SOON', 'align' => 'center', 'bgColor' => '#fff7ed', 'textColor' => '#c2410c'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>Your 14-day free trial will end in 3 days. Upgrade your subscription today to ensure uninterrupted service.', 'textColor' => '#334155'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Upgrade Account Now', 'url' => '#', 'align' => 'center', 'btnColor' => '#ea580c', 'textColor' => '#ffffff'],
                ],
            ],
            [
                'title'            => 'Post-Event Workshop Recording & Slides',
                'email_subject'    => 'Masterclass Recording & Presentation Slides',
                'email_pre_header' => 'In case you missed it: watch the full workshop recording here.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'WORKSHOP RECORDING IS LIVE', 'align' => 'center', 'bgColor' => '#1e1b4b', 'textColor' => '#818cf8'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>Thank you to everyone who joined our live workshop! The full video recording and presentation slides are now available.', 'textColor' => '#334155'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Watch Workshop Video', 'url' => '#', 'align' => 'center', 'btnColor' => '#4f46e5', 'textColor' => '#ffffff'],
                ],
            ],
            [
                'title'            => 'Security Alert & Password Reset Notice',
                'email_subject'    => 'Security Alert: Password Reset Request',
                'email_pre_header' => 'Click the link inside to safely reset your account password.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'Password Reset Request', 'align' => 'center', 'bgColor' => '#ffffff', 'textColor' => '#0f172a'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>We received a request to reset your password. Click the button below to choose a new password. If you didn\'t request this, you can safely ignore this email.', 'textColor' => '#334155'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Reset My Password', 'url' => '#', 'align' => 'center', 'btnColor' => '#2563eb', 'textColor' => '#ffffff'],
                ],
            ],
            [
                'title'            => 'Free Ebook & Lead Magnet Download',
                'email_subject'    => 'Here is your free Growth Playbook download',
                'email_pre_header' => 'Your copy of our latest guide is ready to download.',
                'is_builtin'       => true,
                'created_by'       => 'System',
                'email_body'       => [
                    ['id' => 'blk-1', 'type' => 'header', 'title' => 'YOUR FREE GUIDE IS HERE', 'align' => 'center', 'bgColor' => '#f0fdf4', 'textColor' => '#166534'],
                    ['id' => 'blk-2', 'type' => 'text', 'content' => 'Hi {{first_name}},<br><br>Thank you for requesting our 2026 Customer Growth Playbook! Click below to download your PDF copy instantly.', 'textColor' => '#334155'],
                    ['id' => 'blk-3', 'type' => 'button', 'text' => 'Download Free PDF', 'url' => '#', 'align' => 'center', 'btnColor' => '#16a34a', 'textColor' => '#ffffff'],
                ],
            ],
        ];

        foreach ($templates as $tpl) {
            EmailTemplate::withoutGlobalScope(\App\Models\Scopes\TenantScope::class)->updateOrCreate(
                ['title' => $tpl['title'], 'is_builtin' => true],
                $tpl
            );
        }
    }
}
