<?php

namespace App\Models;

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

class PurchaseItem extends Model
{
    use HasFactory;

    protected $guarded = [];

    protected $casts = [
        'purchase_id' => 'integer',
        'item_id' => 'integer',
        'quantity' => 'integer',
        'purchase_price' => 'float',
        'total_amount' => 'float',
        'stock_before' => 'integer',
        'stock_after' => 'integer',
        'variation_stock_before' => 'integer',
        'variation_stock_after' => 'integer',
        'stock_movement_id' => 'integer',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    public function purchase()
    {
        return $this->belongsTo(Purchase::class);
    }

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

    public function stockMovement()
    {
        return $this->belongsTo(StockMovement::class);
    }
}
