<?php

namespace Modules\ClinicCore\Entities;

use Illuminate\Database\Eloquent\Model;

class ClcMedicineCategory extends Model
{
    protected $table = 'clc_medicine_categories';
    protected $guarded = ['id'];

    public function medicines()
    {
        return $this->hasMany(ClcMedicine::class, 'category_id');
    }

    public function scopeActive($query)
    {
        return $query->where('status', 'active');
    }

    public function scopeForBusiness($query, $businessId)
    {
        return $query->where(function ($q) use ($businessId) {
            $q->whereNull('business_id')->orWhere('business_id', $businessId);
        });
    }
}
