<?php

namespace App\Filament\Resources\Achievements;

use App\Filament\Resources\Achievements\Pages\ListAchievements;
use App\Filament\Resources\Achievements\Schemas\AchievementInfolist;
use App\Filament\Resources\Achievements\Tables\AchievementsTable;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
use Functional\Streaks\Models\Achievement;
use Illuminate\Database\Eloquent\Model;
use UnitEnum;

/**
 * Badges débloqués par StreakService aux paliers de streak — consultation + suppression
 * uniquement, jamais de création/édition manuelle depuis le back-office.
 */
class AchievementResource extends Resource
{
    protected static ?string $model = Achievement::class;

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

    protected static string|UnitEnum|null $navigationGroup = 'Gamification';

    protected static ?int $navigationSort = 2;

    protected static ?string $modelLabel = 'badge';

    protected static ?string $pluralModelLabel = 'badges';

    protected static ?string $recordTitleAttribute = 'key';

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

    public static function table(Table $table): Table
    {
        return AchievementsTable::configure($table);
    }

    public static function canCreate(): bool
    {
        return false;
    }

    public static function canEdit(Model $record): bool
    {
        return false;
    }

    /**
     * @return array<int, string>
     */
    public static function getGloballySearchableAttributes(): array
    {
        return ['key', 'user.name'];
    }

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