<?php

namespace App\Models;

use App\Traits\GlobalStatus;
use Illuminate\Database\Eloquent\Model;

class SpamFilter extends Model
{
    use GlobalStatus;

    public static function isSpam($description, $filterType = 'text', $subject = null)
    {
        $filters = self::active()->where('filter_type', $filterType)->pluck('content');

        foreach ($filters as $filter) {
            $filter = strtolower($filter);
            if (str_contains(strtolower($description), $filter) || ($subject && str_contains(strtolower($subject), $filter))) {
                return true;
            }
        }

        return false;
    }


    public function admin()
    {
        return $this->belongsTo(Admin::class);
    }

}
