<?php

namespace App\Support\Workspaces;

use App\Models\Workspace;

final class WorkspaceResolver
{
    public function resolve(string $value): ?Workspace
    {
        $workspace = Workspace::query()
            ->where('slug', $value)
            ->first();

        if ($workspace !== null) {
            return $workspace;
        }

        if (! ctype_digit($value)) {
            return null;
        }

        return Workspace::query()->whereKey((int) $value)->first();
    }
}
