<?php

namespace App\Filament\Resources\InventoryItemResource\Pages;

use App\Filament\Concerns\ResolvesPanelTenantContext;
use App\Filament\Resources\InventoryItemResource;
use App\Models\ManagedEnvironment;
use App\Support\Workspaces\WorkspaceContext;
use Filament\Resources\Pages\ViewRecord;
use Illuminate\Database\Eloquent\Model;

class ViewInventoryItem extends ViewRecord
{
    use ResolvesPanelTenantContext;

    protected static string $resource = InventoryItemResource::class;

    public function mount(int|string $record): void
    {
        $tenant = static::resolveTenantContextForCurrentPanel();

        if ($tenant instanceof ManagedEnvironment) {
            app(WorkspaceContext::class)->rememberEnvironmentContext($tenant, request());
        }

        parent::mount($record);
    }

    protected function resolveRecord(int|string $key): Model
    {
        return InventoryItemResource::resolveScopedRecordOrFail($key);
    }
}
