<?php

namespace App\Filament\Resources\Accounting\ChartOfAccounts;

use App\Filament\Resources\Accounting\ChartOfAccounts\Pages\CreateChartOfAccount;
use App\Filament\Resources\Accounting\ChartOfAccounts\Pages\EditChartOfAccount;
use App\Filament\Resources\Accounting\ChartOfAccounts\Pages\ListChartOfAccounts;
use App\Filament\Resources\Accounting\ChartOfAccounts\Pages\ViewChartOfAccount;
use App\Filament\Resources\Accounting\ChartOfAccounts\Schemas\ChartOfAccountForm;
use App\Filament\Resources\Accounting\ChartOfAccounts\Schemas\ChartOfAccountInfolist;
use App\Filament\Resources\Accounting\ChartOfAccounts\Tables\ChartOfAccountsTable;
use App\Models\Accounting\ChartOfAccount;
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 ChartOfAccountResource extends Resource
{
    protected static ?string $model = ChartOfAccount::class;

    protected static ?string $navigationLabel = null;

    protected static ?string $modelLabel = null;

    protected static ?string $pluralModelLabel = null;

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

    protected static ?string $recordTitleAttribute = 'code';

    protected static ?int $navigationSort = 1;

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

    public static function getNavigationLabel(): string
    {
        return __('models.Chart of Accounts');
    }

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

    public static function getPluralModelLabel(): string
    {
        return __('models.Chart of Accounts');
    }

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

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

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

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

    public static function getPages(): array
    {
        return [
            'index' => ListChartOfAccounts::route('/'),
            'create' => CreateChartOfAccount::route('/create'),
            'view' => ViewChartOfAccount::route('/{record}'),
            'edit' => EditChartOfAccount::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;
    }
}
