<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $fillable = ['category_id', 'weight_id', 'name', 'price', 'stock', 'active'];

    public function category()
    {
        return $this->belongsTo(Category::class);
    }

    public function weight()
    {
        return $this->belongsTo(Weight::class);
    }

    public function getFullNameAttribute(): string
    {
        $cat = $this->category->name ?? $this->name;
        $wt = $this->weight->label ?? '';
        return $cat . ($wt ? ' - ' . $wt : '');
    }

    public function orderItems()
    {
        return $this->hasMany(OrderItem::class);
    }

    public function purchaseItems()
    {
        return $this->hasMany(PurchaseItem::class);
    }
}
