<?php

namespace App\Filament\Resources\Warehouse;

use App\Filament\Resources\Warehouse\Pages\ListStockRegister;
use App\Filament\Resources\Warehouse\Tables\StockRegisterTable;
use App\Models\Consignment;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Tables\Table;
use BackedEnum;
use UnitEnum;

class StockRegisterResource extends Resource
{
    protected static ?string $model = Consignment::class;

    protected static string|BackedEnum|null $navigationIcon  = null;
    protected static string|UnitEnum|null $navigationGroup = 'Warehouse';
    protected static ?string $navigationLabel = 'Stock Register';
    protected static ?string $slug            = 'warehouse/stock';
    protected static ?int    $navigationSort  = 1;

    public static function canAccess(): bool
    {
        return auth()->user()?->hasPermissionTo('view_stock') ?? false;
    }

    // Warehouse agent cannot create, edit or delete
    public static function canCreate(): bool  { return false; }
    public static function canEdit($record): bool { return false; }
    public static function canDelete($record): bool { return false; }

    // Form is empty — no editing from warehouse view
    public static function form(Schema $schema): Schema
    {
        return $schema->components([]);
    }

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

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

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