<?php

namespace App\Filament\Exports;

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

/**
 * Columns mirror DamageResource::table() exactly.
 */
class DamageExporter extends Exporter
{
    protected static ?string $model = Damage::class;

    public static function getColumns(): array
    {
        return [
            ExportColumn::make('damage_number'),
            ExportColumn::make('branch.name')->label('Branch'),
            ExportColumn::make('product.name')->label('Product'),
            ExportColumn::make('reason.name')->label('Reason'),
            ExportColumn::make('quantity_damaged'),
            ExportColumn::make('unit.code')->label('Unit'),
            ExportColumn::make('total_damage_cost'),
            ExportColumn::make('created_at'),
        ];
    }

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