<?php

namespace Modules\ClinicCore\Database\Seeders;

use Illuminate\Database\Seeder;
use Modules\ClinicCore\Entities\ClcReminderTemplate;

class VaccinationReminderSeeder extends Seeder
{
    public function run()
    {
        $templates = [
            [
                'type'              => 'email_due',
                'name'              => 'Default — Vaccination Due Soon',
                'subject'           => 'Vaccination Reminder for {{pet_name}} — {{vaccine_name}}',
                'body'              => "Dear {{owner_name}},\n\nThis is a friendly reminder that your pet {{pet_name}} ({{pet_species}}) is due for the {{vaccine_name}} vaccination on {{due_date}}.\n\nThat's in {{days_until_due}} — please contact us to schedule an appointment at your earliest convenience.\n\nClinic: {{clinic_name}}\nPhone: {{clinic_phone}}\nEmail: {{clinic_email}}\n\nThank you for keeping {{pet_name}} healthy!\n\nBest regards,\n{{clinic_name}}",
                'is_active'         => true,
                'is_system_default' => true,
            ],
            [
                'type'              => 'email_overdue',
                'name'              => 'Default — Vaccination Overdue',
                'subject'           => 'OVERDUE: {{pet_name}} missed their {{vaccine_name}} vaccination',
                'body'              => "Dear {{owner_name}},\n\nWe noticed that {{pet_name}} ({{pet_species}}) missed their {{vaccine_name}} vaccination that was due on {{due_date}} ({{days_until_due}}).\n\nDelayed vaccinations can put your pet at risk. Please contact us as soon as possible to reschedule.\n\nClinic: {{clinic_name}}\nPhone: {{clinic_phone}}\nEmail: {{clinic_email}}\n\nBest regards,\n{{clinic_name}}",
                'is_active'         => true,
                'is_system_default' => true,
            ],
            [
                'type'              => 'wa_due',
                'name'              => 'Default WhatsApp — Vaccination Due Soon',
                'subject'           => null,
                'body'              => "Hello {{owner_name}} 👋\n\nThis is a reminder from {{clinic_name}} that your pet *{{pet_name}}* is due for the *{{vaccine_name}}* vaccination on *{{due_date}}* (in {{days_until_due}}).\n\nPlease call us on {{clinic_phone}} to book an appointment.\n\nThank you! 🐾",
                'is_active'         => true,
                'is_system_default' => true,
            ],
            [
                'type'              => 'wa_overdue',
                'name'              => 'Default WhatsApp — Vaccination Overdue',
                'subject'           => null,
                'body'              => "Hello {{owner_name}} 👋\n\n⚠️ *Important:* Your pet *{{pet_name}}* missed their *{{vaccine_name}}* vaccination (was due {{due_date}} — {{days_until_due}}).\n\nPlease contact {{clinic_name}} urgently to reschedule.\n📞 {{clinic_phone}}\n\nThank you for keeping {{pet_name}} safe! 🐾",
                'is_active'         => true,
                'is_system_default' => true,
            ],
        ];

        foreach ($templates as $tpl) {
            $existing = ClcReminderTemplate::where('type', $tpl['type'])
                ->whereNull('business_id')
                ->where('is_system_default', true)
                ->first();

            if (!$existing) {
                ClcReminderTemplate::create(array_merge($tpl, ['business_id' => null]));
            }
        }
    }
}
