<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Folder extends Model
    // Relationship: files in this folder   
{
    use HasFactory;

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

    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    protected $fillable = [
        'name',
        'path',
        'parent_id',
        'description',
        'created_by',
    ];

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

     public function files()
    {
        return $this->hasMany(FileMetadata::class, 'folder_id');
    }
}
