<?php

namespace App\Filament\Resources\FailedJobs;

use App\Filament\Resources\FailedJobs\Pages\CompatibleListFailedJobs;
use BackedEnum;
use BinaryBuilds\FilamentFailedJobs\Models\FailedJob;
use BinaryBuilds\FilamentFailedJobs\Resources\FailedJobs\Pages\ViewFailedJob;
use BinaryBuilds\FilamentFailedJobs\Resources\FailedJobs\Schemas\FailedJobInfolist;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;

class CompatibleFailedJobResource extends Resource
{
    protected static ?string $model = FailedJob::class;

    protected static string|BackedEnum|null $navigationIcon = Heroicon::QueueList;

    protected static string|null|\UnitEnum $navigationGroup = 'Admin';

    public static function infolist(Schema $schema): Schema
    {
        return FailedJobInfolist::configure($schema);
    }

    public static function table(Table $table): Table
    {
        return CompatibleFailedJobsTable::configure($table)
            ->defaultSort('id', 'desc');
    }

    public static function getPages(): array
    {
        return [
            'index' => CompatibleListFailedJobs::route('/'),
            'view' => ViewFailedJob::route('/{record}'),
        ];
    }

    /**
     * Only make this resource available in specific panels
     */
    public static function canViewAny(): bool
    {
        // Check if we're in the 0xdash panel or other admin panels
        $panel = filament()->getCurrentPanel();

        return in_array($panel->getId(), ['0xdash', 'admin']);
    }
}
