<?php

namespace App\Filament\Clusters\Loans\LoanOrders;

use App\Filament\Clusters\Loans\LoanOrders\Pages\CreateLoanOrder;
use App\Filament\Clusters\Loans\LoanOrders\Pages\EditLoanOrder;
use App\Filament\Clusters\Loans\LoanOrders\Pages\ListLoanOrders;
use App\Filament\Clusters\Loans\LoanOrders\Pages\ViewLoanOrder;
use App\Filament\Clusters\Loans\LoanOrders\Schemas\LoanOrderForm;
use App\Filament\Clusters\Loans\LoanOrders\Schemas\LoanOrderInfolist;
use App\Filament\Clusters\Loans\LoanOrders\Tables\LoanOrdersTable;
use App\Filament\Clusters\Loans\LoansCluster;
use App\Modules\LoanOrder\Models\LoanOrder;
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 Illuminate\Database\Eloquent\SoftDeletingScope;

class LoanOrderResource extends Resource
{
    protected static ?int $navigationSort = 2;

    protected static ?string $model = LoanOrder::class;

    protected static ?string $cluster = LoansCluster::class;

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

    protected static string|BackedEnum|null $activeNavigationIcon = Heroicon::DocumentPlus;

    protected static ?string $recordTitleAttribute = 'unique_id';

    public static function getNavigationLabel(): string
    {
        return __('New loan order');
    }

    public static function getModelLabel(): string
    {
        return __('module.loan-order::loan-order.loan_order');
    }

    public static function getPluralModelLabel(): string
    {
        return __('module.loan-order::loan-order.loan_orders');
    }

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

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

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

    public static function getRelations(): array
    {
        return [
            //
        ];
    }

    public static function getPages(): array
    {
        return [
            'index' => ListLoanOrders::route('/'),
            'create' => CreateLoanOrder::route('/create'),
            'view' => ViewLoanOrder::route('/{record}'),
            'edit' => EditLoanOrder::route('/{record}/edit'),
        ];
    }

    /**
     * @return Builder<LoanOrder>
     */
    public static function getRecordRouteBindingEloquentQuery(): Builder
    {
        return parent::getRecordRouteBindingEloquentQuery()
            ->withoutGlobalScopes([
                SoftDeletingScope::class,
            ]);
    }
}
