<?php

declare(strict_types=1);

namespace App\Filament\Resources\DberpNumberSequences;

use App\Filament\Concerns\InteractsWithDberpPermissions;
use App\Filament\Resources\DberpNumberSequences\Pages\EditDberpNumberSequence;
use App\Filament\Resources\DberpNumberSequences\Pages\ListDberpNumberSequences;
use App\Filament\Resources\DberpNumberSequences\Schemas\DberpNumberSequenceForm;
use App\Filament\Resources\DberpNumberSequences\Tables\DberpNumberSequencesTable;
use App\Models\DberpNumberSequence;
use App\Services\DberpPermissionService;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Tables\Table;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Model;
use UnitEnum;

class DberpNumberSequenceResource extends Resource
{
    use InteractsWithDberpPermissions;

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

    protected static ?string $recordTitleAttribute = 'name';

    protected static ?int $navigationSort = 30;

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

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

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

    public static function getPages(): array
    {
        return [
            'index' => ListDberpNumberSequences::route('/'),
            'edit' => EditDberpNumberSequence::route('/{record}/edit'),
        ];
    }

    public static function canViewAny(): bool
    {
        return static::allowsPermission(DberpPermissionService::VIEW_NUMBER_SEQUENCE);
    }

    public static function canView(Model $record): bool
    {
        return static::canViewAny();
    }

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

    public static function canEdit(Model $record): bool
    {
        return static::allowsPermission(DberpPermissionService::EDIT_NUMBER_SEQUENCE);
    }

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

    public static function getNavigationGroup(): string|UnitEnum|null
    {
        return __('dberp.nav.system');
    }

    public static function getNavigationIcon(): string|BackedEnum|Htmlable|null
    {
        return null;
    }

    public static function getModelLabel(): string
    {
        return __('dberp.resources.number_sequence.label');
    }

    public static function getPluralModelLabel(): string
    {
        return __('dberp.resources.number_sequence.plural');
    }
}
