<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class TestTemplatesRoute extends Command {
    protected $signature = 'vc:test-templates';
    protected $description = 'Test templates route';
    public function handle() {
        try {
            $biz = 1;
            $templates = \Modules\VetClinic\Entities\VcReminderTemplate::where(function($q) use ($biz) {
                $q->where('business_id', $biz)->orWhereNull('business_id');
            })->orderBy('type')->get();
            $vars = \Modules\VetClinic\Entities\VcReminderTemplate::availableVariables();
            $this->info('Templates: ' . $templates->count() . ', Vars: ' . count($vars));
            foreach ($templates as $t) {
                $this->line($t->type . ' | ' . $t->name . ' | body_len=' . strlen($t->body ?? ''));
                $limited = \Illuminate\Support\Str::limit($t->body ?? '', 300);
                $this->line('  Str::limit OK');
            }
        } catch (\Exception $e) {
            $this->error($e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine());
            $this->line($e->getTraceAsString());
        }
    }
}
