<?php

namespace App\Models;

use App\Casts\TrimmedDecimal;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ProductionOrderMaterial extends Model
{
    /**
     * @var list<string>
     */
    protected $fillable = [
        'production_order_id',
        'purchase_product_id',
        'quantity',
    ];

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'production_order_id' => 'integer',
            'purchase_product_id' => 'integer',
            'quantity' => TrimmedDecimal::class.':3',
        ];
    }

    /**
     * @return BelongsTo<ProductionOrder, $this>
     */
    public function productionOrder(): BelongsTo
    {
        return $this->belongsTo(ProductionOrder::class);
    }

    /**
     * @return BelongsTo<PurchaseProduct, $this>
     */
    public function purchaseProduct(): BelongsTo
    {
        return $this->belongsTo(PurchaseProduct::class);
    }
}
