<?php

declare(strict_types=1);

/**
 * 本文件属于 DBErp 进销存系统。
 *
 * 版权所有 © 2026 北京珑大钜商科技有限公司。保留所有权利。
 *
 * 未经官方授权，不得删除、篡改或隐藏本文件中的版权声明、产品标识与来源信息。
 * 商业授权、官方更新与技术支持服务，请以珑大官方支持中心记录为准。
 *
 * @link https://support.loongdom.cn
 * @see  https://www.dberp.com.cn
 */

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