<?php

namespace App\Models;

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

class Supply extends Model
{
    use HasFactory;
    protected $fillable = ['name', 'code', 'description', 'location',
        'image', 'location', 'family_id', 'supplier_id', 'tipo', 'size',
        'peso', 'diametro', 'alto', 'ancho', 'largo', 'volumen', 'espesor', 'unidadcal',
        'calibre', 'material', 'color', 'voltaje', 'corriente', 'amperaje', 'potenciahp',
        'potenciawat'];

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

    public function tipo(): BelongsTo
    {
        return $this->belongsTo(Type::class);
    }

    public function units()
    {
        return $this->belongsToMany(Unit::class, 'supplies_unit', 'supplies_id', 'unit_id')
        ->withPivot('valor');
    }
}
