<?php

namespace App;

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

class ProductBestSeller extends Model
{
    use HasFactory;

    protected $table = 'product_best_sellers';

    protected $fillable = ['id', 'type', 'category_id', 'manufacturer_id', 'product_id', 'position', 'created_at', 'updated_at'];

    public function category() {
        return $this->belongsTo(Category::class, 'category_id', 'id')->where('is_deleted', false);
    }

    public function manufacturer() {
        return $this->belongsTo(Manufacturer::class, 'manufacturer_id', 'id')->where('is_deleted', false);
    }

    public function product() {
        return $this->belongsTo(Product::class, 'product_id', 'id')->with('category', 'manufacturer')->where('is_deleted', false);
    }

    public function product_public() {
        return $this->belongsTo(Product::class, 'product_id', 'id')->with('category', 'manufacturer')->where('is_deleted', false)->where('is_activated', true);
    }
}
