<?php

namespace Database\Seeders;

use App\Models\SmsTemplate;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;

/**
 * SmsTemplateSeeder
 *
 * Seeds five default SMS communication templates for the SSHIA platform.
 * These templates cover the most critical automated and manual SMS
 * communications sent to members and applicants throughout their
 * engagement with the South Sudan Health Informatics Association.
 *
 * Templates use {placeholder} syntax for dynamic variable substitution
 * at send time. All content is crafted to be professional, concise,
 * and within the 160-character GSM-7 single-segment limit where possible.
 *
 * Uses updateOrCreate keyed on slug for idempotency — safe to re-run.
 */
class SmsTemplateSeeder extends Seeder
{
    public function run(): void
    {
        $templates = [
            [
                'name'        => 'Welcome Member',
                'slug'        => 'welcome-member',
                'content'     => 'Welcome to SSHIA, {name}! Your membership application has been received. Reference: {reference}. We will review and notify you within 5 working days. info@sshia.org',
                'description' => 'Sent automatically to applicants immediately after submitting a membership application. Confirms receipt and provides a reference number for follow-up.',
                'is_active'   => true,
            ],
            [
                'name'        => 'Membership Approved',
                'slug'        => 'membership-approved',
                'content'     => 'Congratulations {name}! Your SSHIA membership has been approved. Member ID: {member_id}. Category: {category}. Log in at sshia.org to access your member portal.',
                'description' => 'Sent to applicants when their membership application is approved by an administrator. Includes the assigned Member ID and membership category.',
                'is_active'   => true,
            ],
            [
                'name'        => 'Training Session Reminder',
                'slug'        => 'training-session-reminder',
                'content'     => 'Reminder: Your SSHIA training "{session_name}" is on {date} at {time}, {venue}. Bring your registration confirmation. Queries: info@sshia.org',
                'description' => 'Sent to registered trainees 24 hours before a scheduled training session. Includes session name, date, time, and venue details.',
                'is_active'   => true,
            ],
            [
                'name'        => 'Payment Confirmation',
                'slug'        => 'payment-confirmation',
                'content'     => 'SSHIA Payment Confirmed. Amount: {currency} {amount}. Purpose: {purpose}. Ref: {reference}. Date: {date}. Thank you. Queries: info@sshia.org',
                'description' => 'Sent to members and applicants upon successful payment processing. Covers membership fees, training fees, and contribution payments.',
                'is_active'   => true,
            ],
            [
                'name'        => 'OTP Verification',
                'slug'        => 'otp-verification',
                'content'     => 'Your SSHIA verification code is: {otp}. Valid for {minutes} minutes. Do not share this code with anyone. If you did not request this, contact info@sshia.org',
                'description' => 'Sent to users during OTP-based login verification or account security actions. The OTP code is time-limited for security.',
                'is_active'   => true,
            ],
        ];

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

        $this->command->info('SmsTemplateSeeder: 5 SMS templates seeded successfully.');
    }
}
