<?php

declare(strict_types=1);

namespace App\Filament\Resources\HealthReports;

use App\Filament\Resources\HealthReports\Pages\CreateHealthReport;
use App\Filament\Resources\HealthReports\Pages\EditHealthReport;
use App\Filament\Resources\HealthReports\Pages\ListHealthReports;
use App\Filament\Resources\HealthReports\Pages\ViewHealthReport;
use App\Filament\Resources\HealthReports\Schemas\HealthReportForm;
use App\Filament\Resources\HealthReports\Tables\HealthReportsTable;
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 HealthReportResource extends Resource
{
    protected static ?string $model = Report::class;

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

    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 HealthReportForm::configure($schema);
    }

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

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

    public static function getPages(): array
    {
        return [
            'index' => ListHealthReports::route('/'),
            'create' => CreateHealthReport::route('/create'),
            'view' => ViewHealthReport::route('/{record}'),
            'edit' => EditHealthReport::route('/{record}/edit'),
        ];
    }

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

    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', 'disease_name', 'diagnosis', 'desc'];
    }
}
