<?php

namespace App\Models;

use App\Traits\Blameable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class CorporateHospital extends Model
{
    use HasFactory, SoftDeletes, Blameable;

    protected $fillable = [
        'corporate_id',
        'organization_id',
        'code',
        'name',
        'description',
        'active',
    ];

    public function corporate()
    {
        return $this->belongsTo(Corporate::class);
    }

    public function scopeFilter($query, array $filters)
    {
        $query->when($filters['search'] ?? false, function ($query, $search) {
            return $query
                    ->where('code', 'like', "%" . $search . "%")
                    ->orWhere('name', 'like', "%" . $search . "%");
        });
    }
}
