<?php

namespace App\Models;

use CodeIgniter\Model;

class NotificationLogModel extends Model
{
    protected $table = 'notification_logs';
    protected $primaryKey = 'id';
    protected $useTimestamps = true;
    protected $allowedFields = ['company_id', 'type', 'related_id', 'channel', 'sent_at'];

    public function alreadySentToday(string $type, int $relatedId): bool
    {
        return $this->where('type', $type)
            ->where('related_id', $relatedId)
            ->where('DATE(sent_at)', date('Y-m-d'))
            ->countAllResults() > 0;
    }
}
