<?php

namespace Modules\Category\Models;

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

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

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


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

    public function category(): BelongsTo
    {
        return $this->belongsTo(self::class);
    }
    public function canteen(): BelongsTo
    {
        return $this->belongsTo(Canteen::class, 'canteen_id');
    }
    /**
     * Get current description of the the Room
     * @return HasOne
     */

    public function currentDescription(): HasOne
    {
        return $this->hasOne(CategoryDescription::class)->where('language_id', currentLanguage()->id);
    }
}
