<?php

namespace App\Models;

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

class FoodOrderItem extends Model
{
    use HasFactory;

    protected $fillable = [
        'food_order_id',
        'menu_item_id',
        'quantity',
        'unit_price',
        'total_price',
        'special_instructions',
    ];

    protected $casts = [
        'quantity' => 'integer',
        'unit_price' => 'decimal:2',
        'total_price' => 'decimal:2',
    ];

    public function foodOrder()
    {
        return $this->belongsTo(FoodOrder::class);
    }

    public function menuItem()
    {
        return $this->belongsTo(MenuItem::class);
    }

    public function getTotalPrice()
    {
        return $this->total_price ?? ($this->quantity * $this->unit_price);
    }

    public function getFormattedPrice()
    {
        return number_format($this->unit_price, 0) . ' د.ع';
    }

    public function getFormattedTotalPrice()
    {
        return number_format($this->getTotalPrice(), 0) . ' د.ع';
    }
}