<?php

namespace Modules\Category\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Modules\Category\Models\CategoryDescription;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Modules\Product\Models\Product;

class Category extends Model
{
    //use soft delete
    use SoftDeletes;

    protected $fillable = [
        'category_id','visits','image'
    ];


    public function sub() :HasMany
    {
        return $this->hasMany(Self::class,'category_id');
    }

    public function category() :BelongsTo
    {
        return $this->belongsTo(Self::class)->withTrashed();
    }
    public function stores() :BelongsTo
    {
        return $this->hasMany(Product::class);
    }
    /**
     * Get current description of the the Room
     * @return HasOne
     */
    public function currentDescription() :HasOne
    {
        return $this->hasOne(CategoryDescription::class)->where('language_id', currentLanguage()->id);
    }
}
