<?php

namespace App\Filament\Resources\Resellers;

use App\Filament\Resources\Resellers\Pages\CreateReseller;
use App\Filament\Resources\Resellers\Pages\EditReseller;
use App\Filament\Resources\Resellers\Pages\ListResellers;
use App\Filament\Resources\Resellers\Schemas\ResellerForm;
use App\Filament\Resources\Resellers\Tables\ResellersTable;
use App\Filament\Resources\Resellers\RelationManagers\OrdersRelationManager;
use App\Filament\Resources\Resellers\RelationManagers\WalletTransactionsRelationManager;
use App\Filament\Resources\Resellers\RelationManagers\WithdrawRequestsRelationManager;
use App\Filament\Resources\Resellers\Widgets\ResellerStatsWidget;
use App\Models\User;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;

class ResellerResource extends Resource
{
    protected static ?string $model = User::class;

    protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-users';

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

    protected static ?string $navigationLabel = 'Reseller List';

    protected static ?string $modelLabel = 'Reseller';

    protected static ?string $pluralModelLabel = 'Reseller List';

    protected static ?int $navigationSort = 2;

    protected static ?string $recordTitleAttribute = 'name';

    public static function getGloballySearchableAttributes(): array
    {
        return ['name', 'email'];
    }

    public static function form(Schema $schema): Schema
    {
        return ResellerForm::configure($schema);
    }

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


    public static function getEloquentQuery(): \Illuminate\Database\Eloquent\Builder
    {
        return parent::getEloquentQuery()->where('role', 'reseller');
    }

    public static function getRelations(): array
    {
        return [
            OrdersRelationManager::class,
            WalletTransactionsRelationManager::class,
            WithdrawRequestsRelationManager::class,
        ];
    }

    public static function getPages(): array
    {
        return [
            'index' => ListResellers::route('/'),
            'create' => CreateReseller::route('/create'),
            'edit' => EditReseller::route('/{record}/edit'),
        ];
    }

    public static function getWidgets(): array
    {
        return [
            ResellerStatsWidget::class,
        ];
    }
}
