<?php

declare(strict_types=1);

namespace App\Filament\Resources\DberpDictionaryTypes;

use App\Filament\Concerns\InteractsWithDberpPermissions;
use App\Filament\Resources\DberpDictionaryTypes\Pages\EditDberpDictionaryType;
use App\Filament\Resources\DberpDictionaryTypes\Pages\ListDberpDictionaryTypes;
use App\Filament\Resources\DberpDictionaryTypes\RelationManagers\ItemsRelationManager;
use App\Filament\Resources\DberpDictionaryTypes\Schemas\DberpDictionaryTypeForm;
use App\Filament\Resources\DberpDictionaryTypes\Tables\DberpDictionaryTypesTable;
use App\Models\DberpDictionaryType;
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 DberpDictionaryTypeResource extends Resource
{
    use InteractsWithDberpPermissions;

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

    protected static ?string $recordTitleAttribute = 'name';

    protected static ?int $navigationSort = 40;

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

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

    public static function getRelations(): array
    {
        return [
            ItemsRelationManager::class,
        ];
    }

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

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

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

    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.dictionary_type.label');
    }

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