<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * @method static whereNull(string $string)
 * @method static create(array $data)
 */
class DocumentationCategory extends Model
{
    protected $fillable = [
        'name',
        'parent_id',
    ];

    // Родитель
    public function parent(): BelongsTo
    {
        return $this->belongsTo(DocumentationCategory::class, 'parent_id');
    }

    // Дети
    public function children()
    {
        return $this->hasMany(self::class, 'parent_id')->with('children');
    }

    // Документы
    public function documents()
    {
        return $this->hasMany(Documentation::class, 'category_id');
    }

    public function childrenRecursive()
    {
        return $this->children()->with('childrenRecursive');
    }
}
