<?php

namespace App;

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

class ProductRelate extends Model
{
    use HasFactory;

    protected $table = 'related_products';

    protected $fillable = ['id', 'product_id', 'related_id', 'created_at', 'updated_at'];

    public function detail() {
        return $this->belongsTo(Product::class, 'related_id', 'id')
            ->with('category_only', 'manufacturer')
            ->notDeleted()
            ->select('id', 'sku', 'name', 'image', 'price_from', 'price_to', 'category_id', 'manufacturer_id');
    }

    public function product() {
        return $this->belongsTo(Product::class, 'related_id', 'id')
            ->isPublished()
            ->select('id', 'sku', 'name', 'image', 'price_from', 'price_to', 'discount', 'discount_core');
    }
}
