<?php

namespace App\Models;

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

class Product extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'slug',
        'brand',
        'size',
        'price',
        'condition',
        'status',
        'category_id',
        'image',
        'stock',
    ];
    // ------------------------------------------------------------

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

    // <--- TAMBAHIN FUNGSI INI UNTUK RELASI KE RIWAYAT STOK --->
    public function logs()
    {
        return $this->hasMany(ProductLog::class)->orderBy('created_at', 'desc');
    }

    public function reviews()
    {
        return $this->hasMany(ProductReview::class)->latest();
    }
}
