<?php

namespace App\Filament\Exports;

use App\Models\ClassCharacteristic;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;

class ClassCharacteristicExporter extends Exporter
{
    protected static ?string $model = ClassCharacteristic::class;

   public static function getColumns(): array
    {
        static $rowNumber = 0;
        return [
           ExportColumn::make('no')
                ->label('NO')
                ->state(function ($record) use (&$rowNumber) {
                    // Increment and return the row number
                    return ++$rowNumber;
                }),
            ExportColumn::make('plant.name')
                ->label('PLANT'),
            ExportColumn::make('item.code')
                ->label('ITEM CODE'),
            ExportColumn::make('aufnr')
                ->label('AUFNR'),
            ExportColumn::make('class')
                ->label('CLASS'),
            ExportColumn::make('arbid')
                ->label('ARBID'),
            ExportColumn::make('gamng')
                ->label('GAMNG'),
            ExportColumn::make('lmnga')
                ->label('LMNGA'),
            ExportColumn::make('gernr')
                ->label('GERNR'),
            ExportColumn::make('zz1_cn_bill_ord')
                ->label('ZZ1 CN BILL ORD'),
            ExportColumn::make('zmm_amps')
                ->label('ZMM AMPSTEXT'),
            ExportColumn::make('zmm_brand')
                ->label('ZMM BRAND'),
            ExportColumn::make('zmm_degreeofprotection')
                ->label('ZMM DEGREEOFPROTECTION'),
            ExportColumn::make('zmm_delivery')
                ->label('ZMM DELIVERY'),
            ExportColumn::make('zmm_dir_rot')
                ->label('ZMM DIR ROT'),
            ExportColumn::make('zmm_discharge')
                ->label('ZMM DISCHARGE'),
            ExportColumn::make('zmm_discharge_max')
                ->label('ZMM DISCHARGE MAX'),
            ExportColumn::make('zmm_discharge_min')
                ->label('ZMM DISCHARGE MIN'),
            ExportColumn::make('zmm_duty')
                ->label('ZMM DUTY'),
            ExportColumn::make('zmm_eff_motor')
                ->label('ZMM EFF MOTOR'),
            ExportColumn::make('zmm_eff_pump')
                ->label('ZMM EFF PUMP'),
            ExportColumn::make('zmm_frequency')
                ->label('ZMM FREQUENCY'),
            ExportColumn::make('zmm_head')
                ->label('ZMM HEAD'),
            ExportColumn::make('zmm_heading')
                ->label('ZMM HEADING'),
            ExportColumn::make('zmm_head_max')
                ->label('ZMM HEAD MAX'),
            ExportColumn::make('zmm_head_minimum')
                ->label('ZMM HEAD MINIMUM'),
            ExportColumn::make('zmm_idx_eff_mtr')
                ->label('ZMM IDX EFF MTR'),
            ExportColumn::make('zmm_idx_eff_pump')
                ->label('ZMM IDX EFF PUMP'),
            ExportColumn::make('zmm_kvacode')
                ->label('ZMM KVACODE'),
            ExportColumn::make('zmm_maxambtemp')
                ->label('ZMM MAXAMBTEMP'),
            ExportColumn::make('zmm_mincoolingflow')
                ->label('ZMM MINCOOLING FLOW'),
            ExportColumn::make('zmm_motorseries')
                ->label('ZMM MOTORSERIES'),
            ExportColumn::make('zmm_motor_model')
                ->label('ZMM MOTOR MODEL'),
            ExportColumn::make('zmm_outlet')
                ->label('ZMM OUTLET'),
            ExportColumn::make('zmm_phase')
                ->label('ZMM PHASE'),
            ExportColumn::make('zmm_pressure')
                ->label('ZMM PRESSURE'),
            ExportColumn::make('zmm_pumpflowtype')
                ->label('ZMM PUMPFLOWTYPE'),
            ExportColumn::make('zmm_pumpseries')
                ->label('ZMM PUMPSERIES'),
            ExportColumn::make('zmm_pump_model')
                ->label('ZMM PUMP MODEL'),
            ExportColumn::make('zmm_ratedpower')
                ->label('ZMM RATEDPOWER'),
            ExportColumn::make('zmm_region')
                ->label('ZMM REGION'),
            ExportColumn::make('zmm_servicefactor')
                ->label('ZMM SERVICEFACTOR'),
            ExportColumn::make('zmm_servicefactormaximumamps')
                ->label('ZMM SERVICEFACTORMAXIMUMAMPS'),
            ExportColumn::make('zmm_speed')
                ->label('ZMM SPEED'),
            ExportColumn::make('zmm_suction')
                ->label('ZMM SUCTION'),
            ExportColumn::make('zmm_suctionxdelivery')
                ->label('ZMM SUCTIONXDELIVERY'),
            ExportColumn::make('zmm_supplysource')
                ->label('ZMM SUPPLYSOURCE'),
            ExportColumn::make('zmm_temperature')
                ->label('ZMM TEMPERATURE'),
            ExportColumn::make('zmm_thrustload')
                ->label('ZMM THRUSTLOAD'),
            ExportColumn::make('zmm_volts')
                ->label('ZMM VOLTS'),
            ExportColumn::make('zmm_wire')
                ->label('ZMM WIRE'),
            ExportColumn::make('zmm_package')
                ->label('ZMM PACKAGE'),
            ExportColumn::make('zmm_pvarrayrating')
                ->label('ZMM PVARRAYRATING'),
            ExportColumn::make('zmm_isi')
                ->label('ZMM ISI'),
            ExportColumn::make('zmm_isimotor')
                ->label('ZMM ISIMOTOR'),
            ExportColumn::make('zmm_isipump')
                ->label('ZMM ISIPUMP'),
            ExportColumn::make('zmm_isipumpset')
                ->label('ZMM ISIPUMPSET'),
            ExportColumn::make('zmm_pumpset_model')
                ->label('ZMM PUMPSET MODEL'),
            ExportColumn::make('zmm_stages')
                ->label('ZMM STAGES'),
            ExportColumn::make('zmm_headrange')
                ->label('ZMM HEADRANGE'),
            ExportColumn::make('zmm_overall_efficiency')
                ->label('ZMM OVERALL EFFICIENCY'),
            ExportColumn::make('zmm_connection')
                ->label('ZMM CONNECTION'),
            ExportColumn::make('zmm_min_bore_size')
                ->label('ZMM MIN BORE SIZE'),
            ExportColumn::make('zmm_isireference')
                ->label('ZMM ISIREFERENCE'),
            ExportColumn::make('zmm_category')
                ->label('ZMM CATEGORY'),
            ExportColumn::make('zmm_submergence')
                ->label('ZMM SUBMERGENCE'),
            ExportColumn::make('zmm_capacitorstart')
                ->label('ZMM CAPACITORSTART'),
            ExportColumn::make('zmm_capacitorrun')
                ->label('ZMM CAPACITORRUN'),
            ExportColumn::make('zmm_inch')
                ->label('ZMM INCH'),
            ExportColumn::make('zmm_motor_type')
                ->label('ZMM MOTOR TYPE'),
            ExportColumn::make('zmm_dismantle_direction')
                ->label('ZMM DISMANTLE DIRECTION'),
            ExportColumn::make('zmm_eff_ovrall')
                ->label('ZMM EFF OVRALL'),
            ExportColumn::make('zmm_bodymoc')
                ->label('ZMM BODYMOC'),
            ExportColumn::make('zmm_rotormoc')
                ->label('ZMM ROTORMOC'),
            ExportColumn::make('zmm_dlwl')
                ->label('ZMM DLWL'),
            ExportColumn::make('zmm_inputpower')
                ->label('ZMM INPUTPOWER'),
            ExportColumn::make('zmm_imp_od')
                ->label('ZMM IMP OD'),
            ExportColumn::make('zmm_ambtemp')
                ->label('ZMM AMBTEMP'),
            ExportColumn::make('zmm_de')
                ->label('ZMM DE'),
            ExportColumn::make('zmm_dischargerange')
                ->label('ZMM DISCHARGERANGE'),
            ExportColumn::make('zmm_efficiency_class')
                ->label('ZMM EFFICIENCY CLASS'),
            ExportColumn::make('zmm_framesize')
                ->label('ZMM FRAMESIZE'),
            ExportColumn::make('zmm_impellerdiameter')
                ->label('ZMM IMPELLERDIAMETER'),
            ExportColumn::make('zmm_insulationclass')
                ->label('ZMM INSULATIONCLASS'),
            ExportColumn::make('zmm_maxflow')
                ->label('ZMM MAXFLOW'),
            ExportColumn::make('zmm_minhead')
                ->label('ZMM MINHEAD'),
            ExportColumn::make('zmm_mtrlofconst')
                ->label('ZMM MTRLOFCONST'),
            ExportColumn::make('zmm_nde')
                ->label('ZMM NDE'),
            ExportColumn::make('zmm_powerfactor')
                ->label('ZMM POWERFACTOR'),
            ExportColumn::make('zmm_tagno')
                ->label('ZMM TANGO'),
            ExportColumn::make('zmm_year')
                ->label('ZMM YEAR'),
            ExportColumn::make('zmm_laser_name')
                ->label('ZMM LASER NAME'),
            ExportColumn::make('zmm_beenote')
                ->label('ZMM BEENOTE'),
            ExportColumn::make('zmm_beenumber')
                ->label('ZMM BEENUMBER'),
            ExportColumn::make('zmm_beestar')
                ->label('ZMM BEESTAR'),
            ExportColumn::make('zmm_logo_ce')
                ->label('ZMM LOGO CE'),
            ExportColumn::make('zmm_codeclass')
                ->label('ZMM CODECLASS'),
            ExportColumn::make('zmm_colour')
                ->label('ZMM COLOUR'),
            ExportColumn::make('zmm_logo_cp')
                ->label('ZMM LOGO CP'),
            ExportColumn::make('zmm_grade')
                ->label('ZMM GRADE'),
            ExportColumn::make('zmm_grwt_pset')
                ->label('ZMM GRWT PSET'),
            ExportColumn::make('zmm_grwt_cable')
                ->label('ZMM GRWT CABLE'),
            ExportColumn::make('zmm_grwt_motor')
                ->label('ZMM GRWT MOTOR'),
            ExportColumn::make('zmm_grwt_pf')
                ->label('ZMM GRWT PF'),
            ExportColumn::make('zmm_grwt_pump')
                ->label('ZMM GRWT PUMP'),
            ExportColumn::make('zmm_isivalve')
                ->label('ZMM ISIVALVE'),
            ExportColumn::make('zmm_isi_wc')
                ->label('ZMM ISI WC'),
            ExportColumn::make('zmm_labelperiod')
                ->label('ZMM LABELPERIOD'),
            ExportColumn::make('zmm_length')
                ->label('ZMM LENGTH'),
            ExportColumn::make('zmm_license_cml_no')
                ->label('ZMM LICENSE CML NO'),
            ExportColumn::make('zmm_mfgmonyr')
                ->label('ZMM MFGMONYR'),
            ExportColumn::make('zmm_modelyear')
                ->label('ZMM MODELYEAR'),
            ExportColumn::make('zmm_motoridentification')
                ->label('ZMM MOTORIDENTIFICATION'),
            ExportColumn::make('zmm_newt_pset')
                ->label('ZMM NEWT PSET'),
            ExportColumn::make('zmm_newt_cable')
                ->label('ZMM NEWT CABLE'),
            ExportColumn::make('zmm_newt_motor')
                ->label('ZMM NEWT MOTOR'),
            ExportColumn::make('zmm_newt_pf')
                ->label('ZMM NEWT PF'),
            ExportColumn::make('zmm_newt_pump')
                ->label('ZMM NEWT PUMP'),
            ExportColumn::make('zmm_logo_nsf')
                ->label('ZMM LOGO NSF'),
            ExportColumn::make('zmm_packtype')
                ->label('ZMM PACKTYPE'),
            ExportColumn::make('zmm_panel')
                ->label('ZMM PANEL'),
            ExportColumn::make('zmm_performance_factor')
                ->label('ZMM PERFORMANCE FACTOR'),
            ExportColumn::make('zmm_pumpidentification')
                ->label('ZMM PUMPIDENTIFICATION'),
            ExportColumn::make('zmm_psettype')
                ->label('ZMM PSETTYPE'),
            ExportColumn::make('zmm_size')
                ->label('ZMM SIZE'),
            ExportColumn::make('zmm_eff_ttl')
                ->label('ZMM EFF TTL'),
            ExportColumn::make('zmm_type')
                ->label('ZMM TYPE'),
            ExportColumn::make('zmm_usp')
                ->label('ZMM USP'),
            ExportColumn::make('created_at')
                ->label('CREATED AT'),
            ExportColumn::make('updated_at')
                ->label('UPDATED AT'),
            ExportColumn::make('created_by')
                ->label('CREATED BY'),
            ExportColumn::make('updated_by')
                ->label('UPDATED BY'),
            ExportColumn::make('deleted_at')
                ->label('DELETED AT')
                ->enabledByDefault(false),
        ];
    }

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