<?php

namespace App\Models;

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

class InventoryTransaction extends Model
{
    use HasFactory;

    protected $fillable = ['inventory_item_id', 'customer_id', 'type', 'quantity', 'unit_price', 'reference', 'note', 'transaction_date', 'created_by'];

    protected $casts = ['quantity' => 'decimal:2', 'unit_price' => 'decimal:2', 'transaction_date' => 'date'];

    public function item()
    {
        return $this->belongsTo(InventoryItem::class, 'inventory_item_id');
    }

    public function customer()
    {
        return $this->belongsTo(Customer::class);
    }

    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by');
    }
}
