<?php

namespace Modules\HR\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
// use Modules\HR\Database\Factories\BiometricDeviceFactory;
use Modules\Core\Traits\HasStatus;

class BiometricDevice extends Model
{
    use HasStatus, HasFactory;

    /**
     * The attributes that are mass assignable.
     */
    protected $fillable = [
        'branch_id',
        'name',
        'device_uid',
        'ip_address',
        'port',
        'location',
        'status',
    ];

    public function scopeSearch($query, ?string $search)
    {
        if (blank($search)) {
            return $query;
        }
        $search = '%' . trim($search) . '%';

        return $query->where('name', 'like', $search)->orWhere('device_uid', 'like', $search)->orWhere('ip_address', 'like', $search)->orWhere('location', 'like', $search);
    }
}
