<?php

namespace App\Filament\Exports;

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

/**
 * Columns mirror ProductBundleResource::table() exactly.
 */
class ProductBundleExporter extends Exporter
{
    protected static ?string $model = ProductBundle::class;

    public static function getColumns(): array
    {
        return [
            ExportColumn::make('sku'),
            ExportColumn::make('name'),
            ExportColumn::make('branch.name')->label('Branch'),
            ExportColumn::make('sale_price'),
            ExportColumn::make('items_count')->label('Items')->counts('items'),
            ExportColumn::make('is_active')->label('Active'),
        ];
    }

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