<?php

namespace Database\Seeders;

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

class MexcoNotificationTemplateSeeder extends Seeder
{
    public function run(): void
    {
        $templates = [
            [
                'code' => 'campus_retention_warning',
                'name' => 'Campus retention warning',
                'subject' => 'MeXCo: {{event_name}} data deletion in {{days_remaining}} days',
                'body' => "Hello {{contact_name}},\n\nYour sponsored campus event \"{{event_name}}\" will have its data permanently deleted on {{deletion_date}} ({{days_remaining}} days remaining).\n\nContact MeXCo support if you need an extension.\n\nMeXCo Platform",
            ],
            [
                'code' => 'invoice_issued',
                'name' => 'Invoice issued',
                'subject' => 'MeXCo invoice {{invoice_number}} for {{event_name}}',
                'body' => "Hello,\n\nAn invoice has been issued for your MeXCo event \"{{event_name}}\".\n\nInvoice: {{invoice_number}}\nAmount: {{amount}}\nDue: {{due_date}}\n\nMeXCo Platform",
            ],
            [
                'code' => 'invoice_overdue',
                'name' => 'Invoice overdue',
                'subject' => 'MeXCo: overdue invoice {{invoice_number}}',
                'body' => "Hello,\n\nInvoice {{invoice_number}} for event \"{{event_name}}\" is overdue.\n\nAmount due: {{amount}}\n\nPlease arrange payment or contact support.\n\nMeXCo Platform",
            ],
            [
                'code' => 'usage_limit_warning',
                'name' => 'Usage limit warning',
                'subject' => 'MeXCo: {{event_name}} approaching {{metric}} limit',
                'body' => "Hello,\n\nEvent \"{{event_name}}\" has reached {{percent}}% of its {{metric}} limit ({{current}} / {{limit}}).\n\nConsider upgrading the event plan.\n\nMeXCo Platform",
            ],
        ];

        foreach ($templates as $template) {
            MexcoNotificationTemplate::query()->updateOrCreate(
                ['code' => $template['code']],
                array_merge($template, ['channel' => 'email', 'is_active' => true])
            );
        }
    }
}
