<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class PurchaseItem extends Model
{
    protected $fillable = [
        'purchase_id', 'product_id', 'sku', 'product_name',
        'qty_ordered', 'qty_received', 'unit_price', 'subtotal',
    ];

    protected function casts(): array
    {
        return [
            'qty_ordered'  => 'integer',
            'qty_received' => 'integer',
            'unit_price'   => 'integer',
            'subtotal'     => 'integer',
        ];
    }

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

    public function product()
    {
        return $this->belongsTo(Product::class);
    }
}
