<?php

namespace App\Models;

use CodeIgniter\Model;

class NotificationTemplateModel extends Model
{
    protected $table         = 'notification_templates';
    protected $allowedFields = ['trigger_key', 'channel', 'subject', 'body', 'is_active'];

    public function find_for(string $triggerKey, string $channel): ?array
    {
        return $this->where('trigger_key', $triggerKey)->where('channel', $channel)->where('is_active', 1)->first();
    }

    public function channelsFor(string $triggerKey): array
    {
        return array_column($this->where('trigger_key', $triggerKey)->where('is_active', 1)->findAll(), 'channel');
    }
}
