<?php

namespace App\Models;

use App\Http\Livewire\Supplies;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Family extends Model
{
    protected $fillable = ['name', 'description', 'parent_id'];
    use HasFactory;

    public function supplies(): HasMany
    {
        return $this->hasMany(Supply::class);
    }

    public function parent(){
        return $this->belongsTo(Family::class);
    }

    public function families(): HasMany
    {
        return $this->hasMany(Family::class, 'parent_id');
    }

    public function units()
    {
        return $this->belongsToMany(Unit::class, 'family_units', 'family_id', 'unit_id')
        ->withPivot('skuy');;
    }
}
