<?php

namespace App\Filament\Resources\Consignments;

use App\Filament\Resources\Consignments\Pages\CreateConsignment;
use App\Filament\Resources\Consignments\Pages\EditConsignment;
use App\Filament\Resources\Consignments\Pages\ListConsignments;
use App\Filament\Resources\Consignments\Schemas\ConsignmentForm;
use App\Filament\Resources\Consignments\Tables\ConsignmentsTable;
use App\Models\Consignment;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Tables\Table;
use BackedEnum;
use UnitEnum;

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

    protected static string|BackedEnum|null $navigationIcon  = null;
    protected static string|UnitEnum|null $navigationGroup = 'Cargo Management';
    protected static ?string $navigationLabel = 'Consignments';
    protected static ?int    $navigationSort  = 2;

    protected static ?string $recordTitleAttribute = 'customer_name';

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

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

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

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

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

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