<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class MaterialCategory extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'description',
        'is_active',
    ];

    protected function casts(): array
    {
        return [
            'is_active' => 'boolean',
        ];
    }

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

    public function machines()
    {
        return $this->belongsToMany(Machine::class, 'machine_material_category');
    }

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