<?php

declare(strict_types=1);

namespace Database\Seeders;

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

class EmailTemplateSeeder extends Seeder
{
    public function run(): void
    {
        $templates = $this->getDefaultTemplates();

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

    /**
     * @return array<int, array{slug: string, name: string, subject: string, body: string, available_variables: array<int, string>}>
     */
    public static function getDefaultTemplates(): array
    {
        return [
            [
                'slug' => 'payment-succeeded',
                'name' => 'Payment Succeeded',
                'subject' => 'Payment of {{currency}} {{amount}} Received',
                'body' => "Hello {{customer_name}}!\n\nWe've successfully processed your payment of **{{currency}} {{amount}}**.\n\nInvoice: #{{invoice_number}}\nDate: {{date}}\n\nThank you for choosing EZSCALE!",
                'available_variables' => ['customer_name', 'amount', 'currency', 'invoice_number', 'date'],
            ],
            [
                'slug' => 'payment-failed',
                'name' => 'Payment Failed',
                'subject' => 'Payment Failed - Action Required',
                'body' => "Hello {{customer_name}},\n\nWe were unable to process your payment of **{{currency}} {{amount}}**.\n\nPayment method: {{payment_method}}\nReason: {{error_message}}\n\nPlease update your payment method to avoid service interruption.\n\nIf you need assistance, please contact our support team.",
                'available_variables' => ['customer_name', 'amount', 'currency', 'payment_method', 'error_message'],
            ],
            [
                'slug' => 'subscription-created',
                'name' => 'Subscription Created',
                'subject' => 'Subscription Confirmed - {{plan_name}}',
                'body' => "Welcome aboard, {{customer_name}}!\n\nYour subscription to **{{plan_name}}** has been created successfully.\n\nAmount: **{{currency}} {{amount}}**\nBilling cycle: **{{billing_cycle}}**\n\nYour service is being provisioned and will be ready shortly.\n\nThank you for choosing EZSCALE!",
                'available_variables' => ['customer_name', 'plan_name', 'amount', 'currency', 'billing_cycle'],
            ],
            [
                'slug' => 'subscription-cancelled',
                'name' => 'Subscription Cancelled',
                'subject' => 'Subscription Cancelled - {{plan_name}}',
                'body' => "Hello {{customer_name}},\n\nYour subscription to **{{plan_name}}** has been cancelled.\n\nCancellation date: {{cancellation_date}}\nService active until: {{end_date}}\n\nYour service will remain active until the end of your current billing period. You can resubscribe at any time to continue using our services.\n\nWe hope to see you again soon!",
                'available_variables' => ['customer_name', 'plan_name', 'cancellation_date', 'end_date'],
            ],
            [
                'slug' => 'service-provisioned',
                'name' => 'Service Provisioned',
                'subject' => 'Your {{service_type}} Service is Ready!',
                'body' => "Hello {{customer_name}}!\n\nYour **{{service_type}}** service has been provisioned and is ready to use.\n\nPlan: **{{plan_name}}**\nHostname: **{{hostname}}**\nIP Address: **{{ip_address}}**\n\nIf you need help getting started, check our knowledge base or contact support.",
                'available_variables' => ['customer_name', 'service_type', 'hostname', 'ip_address', 'plan_name'],
            ],
            [
                'slug' => 'invoice-generated',
                'name' => 'Invoice Generated',
                'subject' => 'Invoice #{{invoice_number}} - {{currency}} {{amount}}',
                'body' => "Hello {{customer_name}},\n\nA new invoice has been generated for your account.\n\nInvoice: **#{{invoice_number}}**\nAmount: **{{currency}} {{amount}}**\nDue date: **{{due_date}}**\n\nThank you for your business!",
                'available_variables' => ['customer_name', 'invoice_number', 'amount', 'currency', 'due_date'],
            ],
            [
                'slug' => 'service-credentials',
                'name' => 'Service Credentials',
                'subject' => 'Your {{service_type}} Server Credentials - EZSCALE',
                'body' => "Hello {{customer_name}}!\n\nYour **{{service_type}}** service has been provisioned and is ready to use.\n\nHere are your access credentials:\n\n**Hostname:** {{hostname}}\n**IP Address:** {{ip_address}}\n**Username:** {{username}}\n**Password:** {{password}}\n\nFor security, we recommend changing your password after first login.\n\nIf you need help, our support team is available 24/7.",
                'available_variables' => ['customer_name', 'service_type', 'hostname', 'username', 'password', 'ip_address'],
            ],
        ];
    }
}
