<?php

namespace App\Models;

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

class Machine extends Model
{
    use HasFactory;

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

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

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

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

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