<?php

namespace App\Filament\Resources\Accounting\JournalEntries;

use App\Filament\Resources\Accounting\JournalEntries\Pages\CreateJournalEntry;
use App\Filament\Resources\Accounting\JournalEntries\Pages\EditJournalEntry;
use App\Filament\Resources\Accounting\JournalEntries\Pages\ListJournalEntries;
use App\Filament\Resources\Accounting\JournalEntries\Pages\ViewJournalEntry;
use App\Filament\Resources\Accounting\JournalEntries\Schemas\JournalEntryForm;
use App\Filament\Resources\Accounting\JournalEntries\Schemas\JournalEntryInfolist;
use App\Filament\Resources\Accounting\JournalEntries\Tables\JournalEntriesTable;
use App\Models\Accounting\JournalEntry;
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 JournalEntryResource extends Resource
{
    protected static ?string $model = JournalEntry::class;

    protected static ?string $navigationLabel = null;

    protected static ?string $modelLabel = null;

    protected static ?string $pluralModelLabel = null;

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

    protected static ?string $recordTitleAttribute = 'entry_number';

    protected static ?int $navigationSort = 2;

    public static function getNavigationGroup(): ?string
    {
        return __('models.Accounting');
    }

    public static function getNavigationLabel(): string
    {
        return __('models.Journal Entries');
    }

    public static function getModelLabel(): string
    {
        return __('models.Journal Entry');
    }

    public static function getPluralModelLabel(): string
    {
        return __('models.Journal Entries');
    }

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

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

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

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

    public static function getPages(): array
    {
        return [
            'index' => ListJournalEntries::route('/'),
            'create' => CreateJournalEntry::route('/create'),
            'view' => ViewJournalEntry::route('/{record}'),
            'edit' => EditJournalEntry::route('/{record}/edit'),
        ];
    }

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

    public static function getNavigationBadge(): ?string
    {
        return getTenantFilteredCount(static::getModel());
    }

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

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

    public static function canDelete($record): bool
    {
        return true;
    }

    public static function canDeleteAny(): bool
    {
        return true;
    }
}
