<?php

namespace App\Filament\Imports;

use App\Models\ClassCharacteristic;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;

class ClassCharacteristicImporter extends Importer
{
    protected static ?string $model = ClassCharacteristic::class;

    public static function getColumns(): array
    {
        return [
            ImportColumn::make('plant')
                ->requiredMapping()
                ->exampleHeader('Plant Name')
                ->example('Ransar Industries-I')
                ->label('Plant Name')
                ->relationship(resolveUsing:'name')
                ->rules(['required']),
            ImportColumn::make('item')
                ->requiredMapping()
                ->exampleHeader('Item Code')
                ->example('630214')
                ->label('Item Code')
                ->relationship(resolveUsing:'code')
                ->rules(['required']),
            ImportColumn::make('aufnr')
                ->label('Aufnr')
                ->exampleHeader('Aufnr')
                ->example(''),
            ImportColumn::make('class')
                ->label('Class')
                ->exampleHeader('Class')
                ->example(''),
            ImportColumn::make('arbid')
                ->label('Arbid')
                ->exampleHeader('Arbid')
                ->example(''),
            ImportColumn::make('gamng')
                ->label('Gamng')
                ->exampleHeader('Gamng')
                ->example(''),
            ImportColumn::make('lmnga')
                ->label('Lmnga')
                ->exampleHeader('Lmnga')
                ->example(''),
            ImportColumn::make('gernr')
                ->label('Gernr')
                ->exampleHeader('Gernr')
                ->example(''),
            ImportColumn::make('zz1_cn_bill_ord')
                ->label('zz1 ccn bill ord')
                ->exampleHeader('zz1 ccn bill ord')
                ->example(''),
            ImportColumn::make('zmm_amps')
                ->label('zmm amps')
                ->exampleHeader('zmm amps')
                ->example(''),
            ImportColumn::make('zmm_brand')
                ->label('zmm brand')
                ->exampleHeader('zmm brand')
                ->example(''),
            ImportColumn::make('zmm_degreeofprotection')
                ->label('zmm degreeofprotection')
                ->exampleHeader('zmm degreeofprotection')
                ->example(''),
            ImportColumn::make('zmm_delivery')
                ->label('zmm delivery')
                ->exampleHeader('zmm delivery')
                ->example(''),
            ImportColumn::make('zmm_dir_rot')
                ->label('zmm dir rot')
                ->exampleHeader('zmm dir rot')
                ->example(''),
            ImportColumn::make('zmm_discharge')
                ->label('zmm discharge')
                ->exampleHeader('zmm discharge')
                ->example(''),
            ImportColumn::make('zmm_discharge_max')
                ->label('zmm discharge max')
                ->exampleHeader('zmm discharge max')
                ->example(''),
            ImportColumn::make('zmm_discharge_min')
                ->label('zmm discharge min')
                ->exampleHeader('zmm discharge min')
                ->example(''),
            ImportColumn::make('zmm_duty')
                ->label('zmm duty')
                ->exampleHeader('zmm duty')
                ->example(''),
            ImportColumn::make('zmm_eff_motor')
                ->label('zmm eff motor')
                ->exampleHeader('zmm eff motor')
                ->example(''),
            ImportColumn::make('zmm_eff_pump')
                ->label('zmm eff pump')
                ->exampleHeader('zmm eff pump')
                ->example(''),
            ImportColumn::make('zmm_frequency')
                ->label('zmm frequency')
                ->exampleHeader('zmm frequency')
                ->example(''),
            ImportColumn::make('zmm_head')
                ->label('zmm head')
                ->exampleHeader('zmm head')
                ->example(''),
            ImportColumn::make('zmm_heading')
                ->label('zmm heading')
                ->exampleHeader('zmm heading')
                ->example(''),
            ImportColumn::make('zmm_head_max')
                ->label('zmm head max')
                ->exampleHeader('zmm head max')
                ->example(''),
            ImportColumn::make('zmm_head_minimum')
                ->label('zmm head minimum')
                ->exampleHeader('zmm head minimum')
                ->example(''),
            ImportColumn::make('zmm_idx_eff_mtr')
                ->label('zmm idx eff mtr')
                ->exampleHeader('zmm idx eff mtr')
                ->example(''),
            ImportColumn::make('zmm_idx_eff_pump')
                ->label('zmm idx eff pump')
                ->exampleHeader('zmm idx eff pump')
                ->example(''),
            ImportColumn::make('zmm_kvacode')
                ->label('zmm kvacode')
                ->exampleHeader('zmm kvacode')
                ->example(''),
            ImportColumn::make('zmm_maxambtemp')
                ->label('zmm maxambtemp')
                ->exampleHeader('zmm maxambtemp')
                ->example(''),
            ImportColumn::make('zmm_mincoolingflow')
                ->label('zmm mincoolingflow')
                ->exampleHeader('zmm mincoolingflow')
                ->example(''),
            ImportColumn::make('zmm_motorseries')
                ->label('zmm motorseries')
                ->exampleHeader('zmm motorseries')
                ->example(''),
            ImportColumn::make('zmm_motor_model')
                ->label('zmm motor model')
                ->exampleHeader('zmm motor model')
                ->example(''),
            ImportColumn::make('zmm_outlet')
                ->label('zmm outlet')
                ->exampleHeader('zmm outlet')
                ->example(''),
            ImportColumn::make('zmm_phase')
                ->label('zmm phase')
                ->exampleHeader('zmm phase')
                ->example(''),
            ImportColumn::make('zmm_pressure')
                ->label('zmm pressure')
                ->exampleHeader('zmm pressure')
                ->example(''),
            ImportColumn::make('zmm_pumpflowtype')
                ->label('zmm pumpflowtype')
                ->exampleHeader('zmm pumpflowtype')
                ->example(''),
            ImportColumn::make('zmm_pumpseries')
                ->label('zmm pumpseries')
                ->exampleHeader('zmm pumpseries')
                ->example(''),
            ImportColumn::make('zmm_pump_model')
                ->label('zmm pump model')
                ->exampleHeader('zmm pump model')
                ->example(''),
            ImportColumn::make('zmm_ratedpower')
                ->label('zmm ratedpower')
                ->exampleHeader('zmm ratedpower')
                ->example(''),
            ImportColumn::make('zmm_region')
                ->label('zmm region')
                ->exampleHeader('zmm region')
                ->example(''),
            ImportColumn::make('zmm_servicefactor')
                ->label('zmm servicefactor')
                ->exampleHeader('zmm servicefactor')
                ->example(''),
            ImportColumn::make('zmm_servicefactormaximumamps')
                ->label('zmm servicefactormaximumamps')
                ->exampleHeader('zmm servicefactormaximumamps')
                ->example(''),
            ImportColumn::make('zmm_speed')
                ->label('zmm speed')
                ->exampleHeader('zmm speed')
                ->example(''),
            ImportColumn::make('zmm_suction')
                ->label('zmm suction')
                ->exampleHeader('zmm suction')
                ->example(''),
            ImportColumn::make('zmm_suctionxdelivery')
                ->label('zmm suctionxdelivery')
                ->exampleHeader('zmm suctionxdelivery')
                ->example(''),
            ImportColumn::make('zmm_supplysource')
                ->label('zmm supplysource')
                ->exampleHeader('zmm supplysource')
                ->example(''),
            ImportColumn::make('zmm_temperature')
                ->label('zmm temperature')
                ->exampleHeader('zmm temperature')
                ->example(''),
            ImportColumn::make('zmm_thrustload')
                ->label('zmm thrustload')
                ->exampleHeader('zmm thrustload')
                ->example(''),
            ImportColumn::make('zmm_volts')
                ->label('zmm volts')
                ->exampleHeader('zmm volts')
                ->example(''),
            ImportColumn::make('zmm_wire')
                ->label('zmm wire')
                ->exampleHeader('zmm wire')
                ->example(''),
            ImportColumn::make('zmm_package')
                ->label('zmm package')
                ->exampleHeader('zmm package')
                ->example(''),
            ImportColumn::make('zmm_pvarrayrating')
                ->label('zmm pvarrayrating')
                ->exampleHeader('zmm pvarrayrating')
                ->example(''),
            ImportColumn::make('zmm_isi')
                ->label('zmm isi')
                ->exampleHeader('zmm isi')
                ->example(''),
            ImportColumn::make('zmm_isimotor')
                ->label('zmm isimotor')
                ->exampleHeader('zmm isimotor')
                ->example(''),
            ImportColumn::make('zmm_isipump')
                ->label('zmm isipump')
                ->exampleHeader('zmm isipump')
                ->example(''),
            ImportColumn::make('zmm_isipumpset')
                ->label('zmm isipumpset')
                ->exampleHeader('zmm isipumpset')
                ->example(''),
            ImportColumn::make('zmm_pumpset_model')
                ->label('zmm pumpset model')
                ->exampleHeader('zmm pumpset model')
                ->example(''),
            ImportColumn::make('zmm_stages')
                ->label('zmm stages')
                ->exampleHeader('zmm stages')
                ->example(''),
            ImportColumn::make('zmm_headrange')
                ->label('zmm headrange')
                ->exampleHeader('zmm headrange')
                ->example(''),
            ImportColumn::make('zmm_overall_efficiency')
                ->label('zmm overall efficiency')
                ->exampleHeader('zmm overall efficiency')
                ->example(''),
            ImportColumn::make('zmm_connection')
                ->label('zmm connection')
                ->exampleHeader('zmm connection')
                ->example(''),
            ImportColumn::make('zmm_min_bore_size')
                ->label('zmm min bore size')
                ->exampleHeader('zmm min bore size')
                ->example(''),
            ImportColumn::make('zmm_isireference')
                ->label('zmm isireference')
                ->exampleHeader('zmm isireference')
                ->example(''),
            ImportColumn::make('zmm_category')
                ->label('zmm category')
                ->exampleHeader('zmm category')
                ->example(''),
            ImportColumn::make('zmm_submergence')
                ->label('zmm submergence')
                ->exampleHeader('zmm submergence')
                ->example(''),
            ImportColumn::make('zmm_capacitorstart')
                ->label('zmm capacitorstart')
                ->exampleHeader('zmm capacitorstart')
                ->example(''),
            ImportColumn::make('zmm_capacitorrun')
                ->label('zmm capacitorrun')
                ->exampleHeader('zmm capacitorrun')
                ->example(''),
            ImportColumn::make('zmm_inch')
                ->label('zmm inch')
                ->exampleHeader('zmm inch')
                ->example(''),
            ImportColumn::make('zmm_motor_type')
                ->label('zmm motor type')
                ->exampleHeader('zmm motor type')
                ->example(''),
            ImportColumn::make('zmm_dismantle_direction')
                ->label('zmm dismantle direction')
                ->exampleHeader('zmm dismantle direction')
                ->example(''),
            ImportColumn::make('zmm_eff_ovrall')
                ->label('zmm eff ovrall')
                ->exampleHeader('zmm eff ovrall')
                ->example(''),
            ImportColumn::make('zmm_bodymoc')
                ->label('zmm bodymoc')
                ->exampleHeader('zmm bodymoc')
                ->example(''),
            ImportColumn::make('zmm_rotormoc')
                ->label('zmm rotormoc')
                ->exampleHeader('zmm rotormoc')
                ->example(''),
            ImportColumn::make('zmm_dlwl')
                ->label('zmm dlwl')
                ->exampleHeader('zmm dlwl')
                ->example(''),
            ImportColumn::make('zmm_inputpower')
                ->label('zmm inputpower')
                ->exampleHeader('zmm inputpower')
                ->example(''),
            ImportColumn::make('zmm_imp_od')
                ->label('zmm imp od')
                ->exampleHeader('zmm imp od')
                ->example(''),
            ImportColumn::make('zmm_ambtemp')
                ->label('zmm ambtemp')
                ->exampleHeader('zmm ambtemp')
                ->example(''),
            ImportColumn::make('zmm_de')
                ->label('zmm de')
                ->exampleHeader('zmm de')
                ->example(''),
            ImportColumn::make('zmm_dischargerange')
                ->label('zmm dischargerange')
                ->exampleHeader('zmm dischargerange')
                ->example(''),
            ImportColumn::make('zmm_efficiency_class')
                ->label('zmm efficiency class')
                ->exampleHeader('zmm efficiency class')
                ->example(''),
            ImportColumn::make('zmm_framesize')
                ->label('zmm framesize')
                ->exampleHeader('zmm framesize')
                ->example(''),
            ImportColumn::make('zmm_impellerdiameter')
                ->label('zmm impellerdiameter')
                ->exampleHeader('zmm impellerdiameter')
                ->example(''),
            ImportColumn::make('zmm_insulationclass')
                ->label('zmm insulationclass')
                ->exampleHeader('zmm insulationclass')
                ->example(''),
            ImportColumn::make('zmm_maxflow')
                ->label('zmm maxflow')
                ->exampleHeader('zmm maxflow')
                ->example(''),
            ImportColumn::make('zmm_minhead')
                ->label('zmm minhead')
                ->exampleHeader('zmm minhead')
                ->example(''),
            ImportColumn::make('zmm_mtrlofconst')
                ->label('zmm mtrlofconst')
                ->exampleHeader('zmm mtrlofconst')
                ->example(''),
            ImportColumn::make('zmm_nde')
                ->label('zmm nde')
                ->exampleHeader('zmm nde')
                ->example(''),
            ImportColumn::make('zmm_powerfactor')
                ->label('zmm powerfactor')
                ->exampleHeader('zmm powerfactor')
                ->example(''),
            ImportColumn::make('zmm_tagno')
                ->label('zmm tagno')
                ->exampleHeader('zmm tagno')
                ->example(''),
            ImportColumn::make('zmm_year')
                ->label('zmm year')
                ->exampleHeader('zmm year')
                ->example(''),
            ImportColumn::make('zmm_laser_name')
                ->label('zmm laser name')
                ->exampleHeader('zmm laser name')
                ->example(''),
            ImportColumn::make('zmm_beenote')
                ->label('zmm beenote')
                ->exampleHeader('zmm beenote')
                ->example(''),
            ImportColumn::make('zmm_beenumber')
                ->label('zmm beenumber')
                ->exampleHeader('zmm beenumber')
                ->example(''),
            ImportColumn::make('zmm_beestar')
                ->label('zmm beenumber')
                ->exampleHeader('zmm beenumber')
                ->example(''),
            ImportColumn::make('zmm_logo_ce')
                ->label('zmm logo ce')
                ->exampleHeader('zmm logo ce')
                ->example(''),
            ImportColumn::make('zmm_codeclass')
                ->label('zmm codeclass')
                ->exampleHeader('zmm codeclass')
                ->example(''),
            ImportColumn::make('zmm_colour')
                ->label('zmm colour')
                ->exampleHeader('zmm colour')
                ->example(''),
            ImportColumn::make('zmm_logo_cp')
                ->label('zmm logo cp')
                ->exampleHeader('zmm logo cp')
                ->example(''),
            ImportColumn::make('zmm_grade')
                ->label('zmm grade')
                ->exampleHeader('zmm grade')
                ->example(''),
            ImportColumn::make('zmm_grwt_pset')
                ->label('zmm grwt pset')
                ->exampleHeader('zmm grwt pset')
                ->example(''),
            ImportColumn::make('zmm_grwt_cable')
                ->label('zmm grwt cable')
                ->exampleHeader('zmm grwt cable')
                ->example(''),
            ImportColumn::make('zmm_grwt_motor')
                ->label('zmm grwt motor')
                ->exampleHeader('zmm grwt motor')
                ->example(''),
            ImportColumn::make('zmm_grwt_pf')
                ->label('zmm grwt pf')
                ->exampleHeader('zmm grwt pf')
                ->example(''),
            ImportColumn::make('zmm_grwt_pump')
                ->label('zmm grwt pump')
                ->exampleHeader('zmm grwt pump')
                ->example(''),
            ImportColumn::make('zmm_isivalve')
                ->label('zmm isivalve')
                ->exampleHeader('zmm isivalve')
                ->example(''),
            ImportColumn::make('zmm_isi_wc')
                ->label('zmm isi wc')
                ->exampleHeader('zmm isi wc')
                ->example(''),
            ImportColumn::make('zmm_labelperiod')
                ->label('zmm labelperiod')
                ->exampleHeader('zmm labelperiod')
                ->example(''),
            ImportColumn::make('zmm_length')
                ->label('zmm length')
                ->exampleHeader('zmm length')
                ->example(''),
            ImportColumn::make('zmm_license_cml_no')
                ->label('zmm license cml no')
                ->exampleHeader('zmm license cml no')
                ->example(''),
            ImportColumn::make('zmm_mfgmonyr')
                ->label('zmm mfgmonyr')
                ->exampleHeader('zmm mfgmonyr')
                ->example(''),
            ImportColumn::make('zmm_modelyear')
                ->label('zmm modelyear')
                ->exampleHeader('zmm modelyear')
                ->example(''),
            ImportColumn::make('zmm_motoridentification')
                ->label('zmm motoridentification')
                ->exampleHeader('zmm motoridentification')
                ->example(''),
            ImportColumn::make('zmm_newt_pset')
                ->label('zmm newt pset')
                ->exampleHeader('zmm newt pset')
                ->example(''),
            ImportColumn::make('zmm_newt_cable')
                ->label('zmm newt cable')
                ->exampleHeader('zmm newt cable')
                ->example(''),
            ImportColumn::make('zmm_newt_motor')
                ->label('zmm newt motor')
                ->exampleHeader('zmm newt motor')
                ->example(''),
            ImportColumn::make('zmm_newt_pf')
                ->label('zmm newt pf')
                ->exampleHeader('zmm newt pf')
                ->example(''),
            ImportColumn::make('zmm_newt_pump')
                ->label('zmm newt pump')
                ->exampleHeader('zmm newt pump')
                ->example(''),
            ImportColumn::make('zmm_logo_nsf')
                ->label('zmm logo nsf')
                ->exampleHeader('zmm logo nsf')
                ->example(''),
            ImportColumn::make('zmm_packtype')
                ->label('zmm packtype')
                ->exampleHeader('zmm packtype')
                ->example(''),
            ImportColumn::make('zmm_panel')
                ->label('zmm panel')
                ->exampleHeader('zmm panel')
                ->example(''),
            ImportColumn::make('zmm_performance_factor')
                ->label('zmm performance factor')
                ->exampleHeader('zmm performance factor')
                ->example(''),
            ImportColumn::make('zmm_pumpidentification')
                ->label('zmm pumpidentification')
                ->exampleHeader('zmm pumpidentification')
                ->example(''),
            ImportColumn::make('zmm_psettype')
                ->label('zmm psettype')
                ->exampleHeader('zmm psettype')
                ->example(''),
            ImportColumn::make('zmm_size')
                ->label('zmm size')
                ->exampleHeader('zmm size')
                ->example(''),
            ImportColumn::make('zmm_eff_ttl')
                ->label('zmm eff ttl')
                ->exampleHeader('zmm eff ttl')
                ->example(''),
            ImportColumn::make('zmm_type')
                ->label('zmm type')
                ->exampleHeader('zmm type')
                ->example(''),
            ImportColumn::make('zmm_usp')
                ->label('zmm usp')
                ->exampleHeader('zmm usp')
                ->example(''),
            ImportColumn::make('created_by')
                ->label('created by')
                ->exampleHeader('created by')
                ->example('Admin'),
            // ImportColumn::make('updated_by'),
        ];
    }

    public function resolveRecord(): ?ClassCharacteristic
    {
        // return ClassCharacteristic::firstOrNew([
        //     // Update existing records, matching them by `$this->data['column_name']`
        //     'email' => $this->data['email'],
        // ]);

        return new ClassCharacteristic();
    }

    public static function getCompletedNotificationBody(Import $import): string
    {
        $body = 'Your class characteristic import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';

        if ($failedRowsCount = $import->getFailedRowsCount()) {
            $body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
        }

        return $body;
    }
}
