<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class ArticleCategory extends BaseModel
{
    protected $table = 'article_categories';

    protected $fillable = ['id', 'name', 'type', 'slug', 'parent_id', 'description', 'position',
                           'is_activated', 'is_deleted', 'created_at', 'updated_at'];

    public function parent()
    {
        return $this->belongsTo(ArticleCategory::class, 'parent_id');
    }

    public function children()
    {
        return $this->hasMany(ArticleCategory::class, 'parent_id');
    }

    public function articles()
    {
        return $this->belongsToMany(Article::class, 'article_category_details', 'article_category_id', 'article_id');
    }

    public function scopeNotDeleted($query)
    {
        return $query->where('is_deleted', false);
    }

    public function scopeActivated($query)
    {
        return $query->where('is_activated', true);
    }
}
