<?php

namespace App\Filament\Resources\WorkoutSessions;

use App\Filament\Resources\WorkoutSessions\Pages\ListWorkoutSessions;
use App\Filament\Resources\WorkoutSessions\Schemas\WorkoutSessionInfolist;
use App\Filament\Resources\WorkoutSessions\Tables\WorkoutSessionsTable;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
use Functional\Tracking\Models\WorkoutSession;
use Illuminate\Database\Eloquent\Model;
use UnitEnum;

/**
 * Séances loguées par les utilisateurs (via l'app) — consultation + suppression uniquement,
 * jamais de création/édition manuelle depuis le back-office.
 */
class WorkoutSessionResource extends Resource
{
    protected static ?string $model = WorkoutSession::class;

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

    protected static string|UnitEnum|null $navigationGroup = 'Entraînement';

    protected static ?int $navigationSort = 3;

    protected static ?string $modelLabel = 'séance';

    protected static ?string $pluralModelLabel = 'séances';

    protected static ?string $recordTitleAttribute = 'title';

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

    public static function table(Table $table): Table
    {
        return WorkoutSessionsTable::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 ['title', 'user.name'];
    }

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