<?php

namespace App\Models;

use App\Traits\BelongsToOrganization;
use App\Traits\BelongsToBranch;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class PurchaseReturnItem extends Model
{
    use HasFactory, BelongsToOrganization, BelongsToBranch;

    protected $fillable = [
        'purchase_return_id',
        'purchase_item_id',
        'product_id',
        'quantity',
        'unit_cost',
        'subtotal',
        'reason',
        'organization_id',
        'branch_id',
    ];

    protected function casts(): array
    {
        return [
            'quantity'  => 'integer',
            'unit_cost' => 'decimal:2',
            'subtotal'  => 'decimal:2',
        ];
    }

    // Relationships

    public function purchaseReturn()
    {
        return $this->belongsTo(PurchaseReturn::class);
    }

    public function purchaseItem()
    {
        return $this->belongsTo(PurchaseItem::class);
    }

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