<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Folder extends Model
{
    protected $fillable = [
        'name',
        'parent_id',
        'project_id',
        //'icon',
        //'color',
        //'description',
    ];

    public function descendants()
    {
        return $this->belongsToMany(Folder::class, 'folder_closure', 'ancestor_id', 'descendant_id')
            ->withPivot('depth');
    }
    
    public function documents()
    {
        return $this->hasMany(Document::class);
    }

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

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

    public function project()
    {
        return $this->belongsTo(Project::class);
    }
}
