<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Folder extends Model
{
    protected $fillable = [
        'workspace_id',
        'parent_id',
        'name',
        'order_index',
    ];

    public function workspace()
    {
        return $this->belongsTo(Workspace::class);
    }

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

    public function subfolders()
    {
        return $this->hasMany(Folder::class, 'parent_id')->orderBy('order_index');
    }

    public function tasks()
    {
        return $this->hasMany(Task::class);
    }
}
