<?php

namespace Database\Seeders;

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

class EmailTemplateSeeder extends Seeder
{
    public function run()
    {
        $templates = [
            [
                'name' => 'Welcome Email',
                'slug' => 'welcome-email',
                'subject' => 'Welcome to The Mini Port!',
                'body' => '<h1>Welcome, {{ $user->name }}!</h1><p>Thank you for joining The Mini Port. We are excited to have you on board.</p>',
                'is_active' => true,
            ],
            [
                'name' => 'Order Confirmation',
                'slug' => 'order-confirmation',
                'subject' => 'Order Confirmation - #{{ $order->id }}',
                'body' => '<h1>Order Confirmed</h1><p>Hi {{ $user->name }}, your order #{{ $order->id }} has been successfully placed.</p>',
                'is_active' => true,
            ],
            [
                'name' => 'Password Reset',
                'slug' => 'password-reset',
                'subject' => 'Reset Your Password',
                'body' => '<p>Click the link below to reset your password:</p><a href="{{ $link }}">Reset Password</a>',
                'is_active' => true,
            ],
            [
                'name' => 'New Inquiry Received',
                'slug' => 'new-inquiry',
                'subject' => 'New Inquiry from {{ $inquiry->name }}',
                'body' => '<h1>New Inquiry</h1><p>You have received a new inquiry from {{ $inquiry->name }}.</p>',
                'is_active' => true,
            ],
            [
                'name' => 'Quote Request',
                'slug' => 'quote-request',
                'subject' => 'New Quote Request',
                'body' => '<h1>Quote Request</h1><p>A new quote request has been submitted.</p>',
                'is_active' => true,
            ],
            // 🟡 Migrated Hardcoded Events
            [
                'name' => 'Subscription Activated',
                'slug' => 'subscription-activated',
                'subject' => 'Subscription Activated - {{ $plan_name }}',
                'body' => '<h1>Subscription Active</h1><p>Your subscription to <strong>{{ $plan_name }}</strong> is now active until {{ $end_date }}.</p>',
                'is_active' => true,
            ],
            [
                'name' => 'Promotion Activated',
                'slug' => 'promotion-activated',
                'subject' => 'Promotion Package Activated',
                'body' => '<h1>Promotion Active</h1><p>Your promotion package <strong>{{ $package_name }}</strong> has been activated.</p>',
                'is_active' => true,
            ],
            [
                'name' => 'New RFQ Match',
                'slug' => 'new-rfq-match',
                'subject' => 'New Buy Lead Match: {{ $product_name }}',
                'body' => '<h1>New Buy Lead Found</h1><p>A new buy lead matching your product <strong>{{ $product_name }}</strong> has been posted.</p><p><a href="{{ $link }}">View Lead</a></p>',
                'is_active' => true,
            ],
            [
                'name' => 'Subscription Expiring',
                'slug' => 'subscription-expiring',
                'subject' => 'Alert: Subscription Expiring Soon',
                'body' => '<h1>Subscription Expiring</h1><p>Your subscription will expire in {{ $days }} days. Please renew to avoid interruption.</p>',
                'is_active' => true,
            ],
            // 🔴 Missing Events
            [
                'name' => 'Quote Accepted',
                'slug' => 'quote-accepted',
                'subject' => 'Quote Accepted by Buyer',
                'body' => '<h1>Quote Accepted!</h1><p>Great news! Your quote for <strong>{{ $product_name }}</strong> has been accepted by {{ $buyer_name }}.</p>',
                'is_active' => true,
            ],
            [
                'name' => 'Quote Rejected',
                'slug' => 'quote-rejected',
                'subject' => 'Quote Update',
                'body' => '<p>Your quote for <strong>{{ $product_name }}</strong> was not accepted by the buyer at this time.</p>',
                'is_active' => true,
            ],
        ];

        foreach ($templates as $template) {
            EmailTemplate::updateOrCreate(
                ['slug' => $template['slug']],
                $template
            );
        }
    }
}
