<?php

declare(strict_types=1);

namespace App\Filament\Resources\RationReports;

use App\Filament\Resources\RationReports\Pages\CreateRationReport;
use App\Filament\Resources\RationReports\Pages\EditRationReport;
use App\Filament\Resources\RationReports\Pages\ListRationReports;
use App\Filament\Resources\RationReports\Pages\ViewRationReport;
use App\Filament\Resources\RationReports\Schemas\RationReportForm;
use App\Filament\Resources\RationReports\Tables\RationReportsTable;
use App\Models\Report;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use UnitEnum;

class RationReportResource extends Resource
{
    protected static ?string $model = Report::class;

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

    protected static ?string $recordTitleAttribute = 'title';

    protected static ?string $navigationLabel = 'جیره و تغذیه';

    protected static ?string $modelLabel = 'گزارش جیره';

    protected static ?string $pluralModelLabel = 'گزارشات جیره';

    protected static string|null|UnitEnum $navigationGroup = 'گزارشات و آمار';

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

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

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

    public static function getPages(): array
    {
        return [
            'index' => ListRationReports::route('/'),
            'create' => CreateRationReport::route('/create'),
            'view' => ViewRationReport::route('/{record}'),
            'edit' => EditRationReport::route('/{record}/edit'),
        ];
    }

    public static function getEloquentQuery(): Builder
    {
        return parent::getEloquentQuery()
            ->where('type', Report::TYPE_RATION);
    }

    public static function getRecordRouteBindingEloquentQuery(): Builder
    {
        return parent::getRecordRouteBindingEloquentQuery()
            ->withoutGlobalScopes([SoftDeletingScope::class]);
    }

    public static function getGlobalSearchResultTitle(Model $record): string|Htmlable
    {
        return $record->title;
    }

    public static function getGloballySearchableAttributes(): array
    {
        return ['title', 'ration_type', 'period', 'desc'];
    }
}
