<?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;

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

    protected $fillable = [
        'status','is_required','category_id'
    ];


    public function category() :HasMany
    {
        return $this->hasMany(Category::class,'category_id');
    }
    
    public function descriptions($language_id = null)
    {
        return AttributeDescription::where('attribute_id',$this->id)->where('language_id', $language_id)->first();
    }
    
    public function currentDescription() :HasOne
    {
        return $this->hasOne(AttributeDescription::class)->where('language_id', currentLanguage()->id);
    }
}
