<?php

namespace App\Models;

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

class FileMetadata extends Model
{
    use HasFactory;

    protected $table = 'file_metadata';

    protected $fillable = [
        'file_path',
        'file_name',
        'folder_id',
        'meta_tag',
        'meta_value',
        'uploaded_by',
        'comment',
    ];

    /**
     * Relationship with folder
     */
    public function folder()
    {
        return $this->belongsTo(Folder::class);
    }

    /**
     * Relationship with user who uploaded
     */
    public function uploader()
    {
        return $this->belongsTo(User::class, 'uploaded_by');
    }

    /**
     * Get all metadata for a specific file
     */
    public static function getFileMetadata($filePath)
    {
        return self::where('file_path', $filePath)->get();
    }

    /**
     * Get files by metadata tag and value
     */
    public static function getFilesByMetadata($tag, $value)
    {
        return self::where('meta_tag', $tag)
                   ->where('meta_value', $value)
                   ->get();
    }
}
