<?php

namespace App\Models;

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

class KitchenIssuanceItem extends Model
{
    use HasFactory;

    protected $fillable = [
        'kitchen_issuance_id',
        'inventory_item_id',
        'quantity',
        'unit',
        'unit_cost',
        'total_cost',
        'notes',
    ];

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

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

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

    public function getFormattedQuantityAttribute(): string
    {
        return number_format($this->quantity, 3) . ' ' . $this->unit;
    }

    public function getFormattedCostAttribute(): string
    {
        return 'KES ' . number_format($this->total_cost, 2);
    }
}
