<?php

namespace App\Filament\Exports;

use App\Models\Volunteer;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
use Illuminate\Support\Number;

class VolunteerExporter extends Exporter
{
    protected static ?string $model = Volunteer::class;

    public static function getColumns(): array
    {
        return [
            ExportColumn::make('lan_id'),
            ExportColumn::make('first_name'),
            ExportColumn::make('surname'),
            ExportColumn::make('phone'),
            ExportColumn::make('email'),
            ExportColumn::make('gdpr'),
            ExportColumn::make('areas'),
        ];
    }

    public static function getCompletedNotificationBody(Export $export): string
    {
        $body = 'Your volunteer export has completed and ' . Number::format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';

        if ($failedRowsCount = $export->getFailedRowsCount()) {
            $body .= ' ' . Number::format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
        }

        return $body;
    }
}
