<?php

namespace App\Modules\Inventory\Models;

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

class StoreRequisitionItem extends Model
{
    use HasFactory;

    protected $fillable = [
        'store_requisition_id',
        'product_id',
        'requested_qty',
        'approved_qty',
        'remark',
    ];

    protected $casts = [
        'requested_qty' => 'decimal:2',
        'approved_qty' => 'decimal:2',
    ];

    /**
     * 所屬叫貨單
     */
    public function requisition(): BelongsTo
    {
        return $this->belongsTo(StoreRequisition::class, 'store_requisition_id');
    }

    /**
     * 關聯商品（同模組）
     */
    public function product(): BelongsTo
    {
        return $this->belongsTo(Product::class);
    }
}
