<?php

declare(strict_types=1);

namespace App\Http\Controllers\Helpers;


use App\Models\FileList;
use Hypervel\Http\Request;
use App\Http\Controllers\FilesMainController;
use Hypervel\Database\Eloquent\Model;

class QueryHelper
{

    public static function findOrNullByHashOrId(
        int|string|Model|false $hashOrId,
        string $modelClass
    ): false|Model {

        if (!$hashOrId) {
            return false;
        }


        if ($hashOrId instanceof Model) {
            return $hashOrId;
        }


        if (!is_subclass_of($modelClass, Model::class)) {
            throw new \InvalidArgumentException('Invalid model class');
        }

        if (is_int($hashOrId)) {
            return $modelClass::find($hashOrId);
        }

        return $modelClass::where('hashkey', $hashOrId)->first();
    }

}