<?php

namespace App\Models;

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

class MaterialType extends Model
{
    use HasFactory;

    protected $fillable = [
        'category',
        'name',
        'unit',
        'default_unit_price',
        'stock_quantity',
        'active',
    ];

    protected $casts = [
        'active' => 'boolean',
        'default_unit_price' => 'decimal:4',
        'stock_quantity' => 'decimal:3',
    ];

    public function expenses(): HasMany
    {
        return $this->hasMany(MaterialExpense::class);
    }

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

    public function scopeFeed($query)
    {
        return $query->where('category', 'feed_supplements');
    }
}
