<?php

namespace App\Filament\Exports;

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

/**
 * Columns mirror MainCategoryResource::table() exactly.
 */
class MainCategoryExporter extends Exporter
{
    protected static ?string $model = MainCategory::class;

    public static function getColumns(): array
    {
        return [
            ExportColumn::make('name'),
            ExportColumn::make('sort_code')->label('Code'),
            ExportColumn::make('sub_categories_count')->label('Sub-categories')->counts('subCategories'),
            ExportColumn::make('products_count')->label('Products')->counts('products'),
            ExportColumn::make('is_active')->label('Active'),
        ];
    }

    public static function getCompletedNotificationBody(Export $export): string
    {
        $body = 'Your main category 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;
    }
}
