<?php

declare(strict_types=1);


namespace App\Filament\Resources\Posts;

use App\Filament\Resources\Posts\Pages\CreatePost;
use App\Filament\Resources\Posts\Pages\EditPost;
use App\Filament\Resources\Posts\Pages\ListPosts;
use App\Filament\Resources\Posts\Schemas\PostForm;
use App\Filament\Resources\Posts\Tables\PostsTable;
use App\Models\Post;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;

class PostResource extends Resource
{
    protected static \UnitEnum|string|null $navigationGroup = '内容';

    protected static ?string $navigationLabel = '文章';

    protected static ?string $modelLabel = '文章';

    protected static ?string $pluralModelLabel = '文章';

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

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

    public static function form(Schema $schema): Schema
    {
        $schema = PostForm::configure($schema);

        // 插件注入：会员付费设置、AI 选项等后台扩展
        app(\App\Blog\Support\PluginManager::class)->doAction('filament.post_form', $schema);

        return $schema;
    }

    public static function table(Table $table): Table
    {
        $table = PostsTable::configure($table);

        // 插件注入：价格、会员专享等表格列
        app(\App\Blog\Support\PluginManager::class)->doAction('filament.post_table', $table);

        return $table;
    }

    public static function getRelations(): array
    {
        return [
            \App\Filament\Resources\Posts\RelationManagers\CommentsRelationManager::class,
        ];
    }

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