<?php

namespace App\Models;

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

class MaterialComponent extends Model
{
    use HasFactory;

    protected $table = 'material_components';

    protected $fillable = [
        'material_id',
        'component_material_id',
        'qty',
    ];

    protected $casts = [
        'qty' => 'decimal:4',
    ];

    public function material(): BelongsTo
    {
        return $this->belongsTo(Material::class, 'material_id');
    }

    public function componentMaterial(): BelongsTo
    {
        return $this->belongsTo(Material::class, 'component_material_id');
    }
}