<?php

namespace App\Models;

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

class FatteningLotFeedIntakeItem extends Model
{
    use HasFactory;

    protected $fillable = [
        'fattening_lot_feed_intake_id',
        'material_type_id',
        'quantity',
        'unit_price',
        'line_cost',
    ];

    protected $casts = [
        'quantity' => 'decimal:3',
        'unit_price' => 'decimal:4',
        'line_cost' => 'decimal:2',
    ];

    public function intake(): BelongsTo
    {
        return $this->belongsTo(FatteningLotFeedIntake::class, 'fattening_lot_feed_intake_id');
    }

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

    public function materialExpense(): HasOne
    {
        return $this->hasOne(MaterialExpense::class, 'fattening_lot_feed_intake_item_id');
    }
}
