<?php

namespace App\Filament\Resources\OpeningBalances;

use App\Filament\Resources\OpeningBalances\Pages\CreateOpeningBalance;
use App\Filament\Resources\OpeningBalances\Pages\EditOpeningBalance;
use App\Filament\Resources\OpeningBalances\Pages\ListOpeningBalances;
use App\Filament\Resources\OpeningBalances\Schemas\OpeningBalanceForm;
use App\Filament\Resources\OpeningBalances\Tables\OpeningBalancesTable;
use App\Models\OpeningBalance;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;

class OpeningBalanceResource extends Resource
{
    protected static ?string $model = OpeningBalance::class;

    protected static ?string $navigationLabel = null;

    protected static ?string $modelLabel = null;

    protected static ?string $pluralModelLabel = null;

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

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

    protected static ?int $navigationSort = 5;

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

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

    public static function getEloquentQuery(): \Illuminate\Database\Eloquent\Builder
    {
        return parent::getEloquentQuery()
            ->with(['product.baseUnit', 'warehouse', 'tenant', 'createdBy', 'updatedBy']);
    }

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

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

    public static function getNavigationGroup(): string|null
    {
        return __('filament.navigation_groups.products');
    }
    public static function getNavigationLabel(): string
    {
        return __('filament/admin/opening_balance_resource.navigation_label');
    }
    public static function getModelLabel(): string
    {
        return __('filament/admin/opening_balance_resource.model_label');
    }
    public static function getPluralModelLabel(): string
    {
        return __('filament/admin/opening_balance_resource.plural_model_label');
    }

    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;
    }
}
