<?php

declare(strict_types=1);

namespace App\Models;

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

class ReportRationIngredient extends Model
{
    protected $guarded = ['id', 'created_at', 'updated_at'];

    protected $casts = [
        'quantity_per_unit' => 'decimal:3',
        'price_per_unit' => 'decimal:0',
    ];

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

    public function getTotalPriceAttribute(): float
    {
        return (float) $this->quantity_per_unit * (float) $this->price_per_unit;
    }
}
