<?php

namespace App\Filament\Exports;

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

class QrcodeRecordExporter extends Exporter
{
    protected static ?string $model = QrcodeRecord::class;

    public static function getColumns(): array
    {
        return [

            ExportColumn::make('outlet_id')
            ->label('店號'),
            ExportColumn::make('outlet_name')
            ->label('店名'),
            ExportColumn::make('representative_id')
            ->label('Representative ID'),
            ExportColumn::make('qr_generated_at')
            ->label('QR Code 產生時間'),

        ];
    }

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