<?php
declare(strict_types=1);

namespace App\Models;

use App\Core\Model;

final class EmailTemplate extends Model
{
    public function findByKey(string $key): ?array
    {
        $stmt = $this->db->prepare("
            SELECT *
            FROM email_templates
            WHERE template_key = :template_key AND is_active = 1
            LIMIT 1
        ");
        $stmt->execute([':template_key' => $key]);
        $row = $stmt->fetch();
        return $row ?: null;
    }

    public function all(): array
    {
        return $this->db->query("SELECT * FROM email_templates ORDER BY template_key ASC")->fetchAll();
    }
}
