<?php

namespace App\Filament\Resources\Manage\Partners;

use App\Filament\Resources\Manage\Partners\Infolists\PartnerInfolist;
use App\Filament\Resources\Manage\Partners\Pages\ManagePartners;
use App\Filament\Resources\Manage\Partners\Pages\ViewPartner;
use App\Filament\Resources\Manage\Partners\Tables\PartnerTable;
use App\Models\User;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use UnitEnum;

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

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

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

    protected static ?string $navigationLabel = 'Rekanan';

    protected static ?int $navigationSort = 1;

    protected static ?string $slug = 'manage/partners';

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

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

    public static function getEloquentQuery(): Builder
    {
        return parent::getEloquentQuery()
            ->role('Perusahaan')
            ->whereHas('company');
    }

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