<?php

namespace App\Models;

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

class MaterialExpense extends Model
{
    use HasFactory;

    protected $fillable = [
        'material_type_id',
        'expense_date',
        'quantity',
        'bundle_count',
        'unit_cost',
        'total_cost',
        'fattening_lot_id',
        'adds_to_inventory',
        'notes',
        'user_id',
        'fattening_lot_feed_intake_item_id',
    ];

    protected $casts = [
        'expense_date' => 'date',
        'quantity' => 'decimal:3',
        'unit_cost' => 'decimal:2',
        'total_cost' => 'decimal:2',
        'adds_to_inventory' => 'boolean',
    ];

    public function materialType(): BelongsTo
    {
        return $this->belongsTo(MaterialType::class);
    }

    public function fatteningLot(): BelongsTo
    {
        return $this->belongsTo(FatteningLot::class);
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    public function feedIntakeItem(): BelongsTo
    {
        return $this->belongsTo(FatteningLotFeedIntakeItem::class, 'fattening_lot_feed_intake_item_id');
    }
}
