<?php

namespace App\Domain\WhatsApp;

use App\Enums\WaTemplateKey;
use App\Models\Tenant;
use App\Models\WaTemplate;

/**
 * Default bilingual templates seeded into every clinic; owners may edit them.
 * Tokens use {token} and are filled by TemplateRenderer.
 */
class DefaultTemplates
{
    public static function seed(Tenant $tenant): void
    {
        foreach (self::all() as $key => $bodies) {
            WaTemplate::withoutEvents(fn () => WaTemplate::create([
                'tenant_id' => $tenant->id,
                'key' => $key,
                'body_ar' => $bodies['ar'],
                'body_en' => $bodies['en'],
                'enabled' => true,
            ]));
        }
    }

    /** @return array<string, array{ar:string, en:string}> */
    public static function all(): array
    {
        return [
            WaTemplateKey::Confirmation->value => [
                'ar' => "مرحباً {patient} 👋\nتم تأكيد موعدك في {clinic} مع {dentist} يوم {date} الساعة {time}.\nنراك قريباً!",
                'en' => "Hi {patient} 👋\nYour appointment at {clinic} with {dentist} is confirmed for {date} at {time}.\nSee you soon!",
            ],
            WaTemplateKey::Reminder24h->value => [
                'ar' => "تذكير: موعدك في {clinic} غداً {date} الساعة {time} مع {dentist}.\nهل ستحضر؟ رجاءً ردّ بـ (نعم) للتأكيد أو (لا) للإلغاء.",
                'en' => "Reminder: your appointment at {clinic} is tomorrow {date} at {time} with {dentist}.\nWill you attend? Reply YES to confirm or NO to cancel.",
            ],
            WaTemplateKey::Reminder1h->value => [
                'ar' => "موعدك في {clinic} بعد ساعة، الساعة {time}. نراك قريباً! 🦷",
                'en' => "Your appointment at {clinic} is in one hour, at {time}. See you soon! 🦷",
            ],
            WaTemplateKey::ReviewHigh->value => [
                'ar' => "شكراً لزيارتك {clinic} يا {patient} 🌟\nيسعدنا تقييمك على Google: {link}",
                'en' => "Thank you for visiting {clinic}, {patient} 🌟\nWe'd love your review on Google: {link}",
            ],
            WaTemplateKey::ReviewLow->value => [
                'ar' => "نأسف إن لم تكن تجربتك في {clinic} مثالية يا {patient}.\nرأيك يهمنا — شاركنا ملاحظاتك هنا: {link}",
                'en' => "We're sorry your visit to {clinic} wasn't perfect, {patient}.\nYour feedback matters — tell us here: {link}",
            ],
            WaTemplateKey::Recall->value => [
                'ar' => "مرحباً {patient} 🦷\nحان وقت زيارتك الدورية في {clinic} ({reason}).\nاحجز موعدك الآن: {link}",
                'en' => "Hi {patient} 🦷\nIt's time for your check-up at {clinic} ({reason}).\nBook now: {link}",
            ],
            WaTemplateKey::InstallmentDue->value => [
                'ar' => "تذكير ودّي يا {patient}: قسط بقيمة {amount} د.ع مستحق بتاريخ {due_date} في {clinic}.\nشكراً لك 🙏",
                'en' => "Friendly reminder, {patient}: an installment of {amount} IQD is due on {due_date} at {clinic}.\nThank you 🙏",
            ],
            WaTemplateKey::TreatmentPlan->value => [
                'ar' => "مرحباً {patient}، إليك خطتك العلاجية من {clinic} 📋",
                'en' => "Hi {patient}, here is your treatment plan from {clinic} 📋",
            ],
            WaTemplateKey::Invoice->value => [
                'ar' => "مرحباً {patient}، إليك فاتورتك من {clinic} 🧾",
                'en' => "Hi {patient}, here is your invoice from {clinic} 🧾",
            ],
        ];
    }
}
