<?php

namespace App\Filament\Imports;

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

class ItemCharacteristicImporter extends Importer
{
    protected static ?string $model = ItemCharacteristic::class;

    public static function getColumns(): array
    {
        return [
            ImportColumn::make('plant')
                ->requiredMapping()
                ->relationship()
                ->rules(['required']),
            ImportColumn::make('item')
                ->requiredMapping()
                ->relationship()
                ->rules(['required']),
            ImportColumn::make('class'),
            ImportColumn::make('zz1_cn_bill_ord'),
            ImportColumn::make('zmm_amps'),
            ImportColumn::make('zmm_brand'),
            ImportColumn::make('zmm_degreeofprotection'),
            ImportColumn::make('zmm_delivery'),
            ImportColumn::make('zmm_dir_rot'),
            ImportColumn::make('zmm_discharge'),
            ImportColumn::make('zmm_discharge_max'),
            ImportColumn::make('zmm_discharge_min'),
            ImportColumn::make('zmm_duty'),
            ImportColumn::make('zmm_eff_motor'),
            ImportColumn::make('zmm_eff_pump'),
            ImportColumn::make('zmm_frequency'),
            ImportColumn::make('zmm_head'),
            ImportColumn::make('zmm_heading'),
            ImportColumn::make('zmm_head_max'),
            ImportColumn::make('zmm_head_minimum'),
            ImportColumn::make('zmm_idx_eff_mtr'),
            ImportColumn::make('zmm_idx_eff_pump'),
            ImportColumn::make('zmm_kvacode'),
            ImportColumn::make('zmm_maxambtemp'),
            ImportColumn::make('zmm_mincoolingflow'),
            ImportColumn::make('zmm_motorseries'),
            ImportColumn::make('zmm_motor_model'),
            ImportColumn::make('zmm_outlet'),
            ImportColumn::make('zmm_phase'),
            ImportColumn::make('zmm_pressure'),
            ImportColumn::make('zmm_pumpflowtype'),
            ImportColumn::make('zmm_pumpseries'),
            ImportColumn::make('zmm_pump_model'),
            ImportColumn::make('zmm_ratedpower'),
            ImportColumn::make('zmm_region'),
            ImportColumn::make('zmm_servicefactor'),
            ImportColumn::make('zmm_servicefactormaximumamps'),
            ImportColumn::make('zmm_speed'),
            ImportColumn::make('zmm_suction'),
            ImportColumn::make('zmm_suctionxdelivery'),
            ImportColumn::make('zmm_supplysource'),
            ImportColumn::make('zmm_temperature'),
            ImportColumn::make('zmm_thrustload'),
            ImportColumn::make('zmm_volts'),
            ImportColumn::make('zmm_wire'),
            ImportColumn::make('zmm_package'),
            ImportColumn::make('zmm_pvarrayrating'),
            ImportColumn::make('zmm_isi'),
            ImportColumn::make('zmm_isimotor'),
            ImportColumn::make('zmm_isipump'),
            ImportColumn::make('zmm_isipumpset'),
            ImportColumn::make('zmm_pumpset_model'),
            ImportColumn::make('zmm_stages'),
            ImportColumn::make('zmm_headrange'),
            ImportColumn::make('zmm_overall_efficiency'),
            ImportColumn::make('zmm_connection'),
            ImportColumn::make('zmm_min_bore_size'),
            ImportColumn::make('zmm_isireference'),
            ImportColumn::make('zmm_category'),
            ImportColumn::make('zmm_submergence'),
            ImportColumn::make('zmm_capacitorstart'),
            ImportColumn::make('zmm_capacitorrun'),
            ImportColumn::make('zmm_inch'),
            ImportColumn::make('zmm_motor_type'),
            ImportColumn::make('zmm_dismantle_direction'),
            ImportColumn::make('zmm_eff_ovrall'),
            ImportColumn::make('zmm_bodymoc'),
            ImportColumn::make('zmm_rotormoc'),
            ImportColumn::make('zmm_dlwl'),
            ImportColumn::make('zmm_inputpower'),
            ImportColumn::make('zmm_imp_od'),
            ImportColumn::make('zmm_ambtemp'),
            ImportColumn::make('zmm_de'),
            ImportColumn::make('zmm_dischargerange'),
            ImportColumn::make('zmm_efficiency_class'),
            ImportColumn::make('zmm_framesize'),
            ImportColumn::make('zmm_impellerdiameter'),
            ImportColumn::make('zmm_insulationclass'),
            ImportColumn::make('zmm_maxflow'),
            ImportColumn::make('zmm_minhead'),
            ImportColumn::make('zmm_mtrlofconst'),
            ImportColumn::make('zmm_nde'),
            ImportColumn::make('zmm_powerfactor'),
            ImportColumn::make('zmm_tagno'),
            ImportColumn::make('zmm_year'),
            ImportColumn::make('zmm_laser_name'),
            ImportColumn::make('zmm_beenote'),
            ImportColumn::make('zmm_beenumber'),
            ImportColumn::make('zmm_beestar'),
            ImportColumn::make('zmm_logo_ce'),
            ImportColumn::make('zmm_codeclass'),
            ImportColumn::make('zmm_colour'),
            ImportColumn::make('zmm_logo_cp'),
            ImportColumn::make('zmm_grade'),
            ImportColumn::make('zmm_grwt_pset'),
            ImportColumn::make('zmm_grwt_cable'),
            ImportColumn::make('zmm_grwt_motor'),
            ImportColumn::make('zmm_grwt_pf'),
            ImportColumn::make('zmm_grwt_pump'),
            ImportColumn::make('zmm_isivalve'),
            ImportColumn::make('zmm_isi_wc'),
            ImportColumn::make('zmm_labelperiod'),
            ImportColumn::make('zmm_length'),
            ImportColumn::make('zmm_license_cml_no'),
            ImportColumn::make('zmm_mfgmonyr'),
            ImportColumn::make('zmm_modelyear'),
            ImportColumn::make('zmm_motoridentification'),
            ImportColumn::make('zmm_newt_pset'),
            ImportColumn::make('zmm_newt_cable'),
            ImportColumn::make('zmm_newt_motor'),
            ImportColumn::make('zmm_newt_pf'),
            ImportColumn::make('zmm_newt_pump'),
            ImportColumn::make('zmm_logo_nsf'),
            ImportColumn::make('zmm_packtype'),
            ImportColumn::make('zmm_panel'),
            ImportColumn::make('zmm_performance_factor'),
            ImportColumn::make('zmm_pumpidentification'),
            ImportColumn::make('zmm_psettype'),
            ImportColumn::make('zmm_size'),
            ImportColumn::make('zmm_eff_ttl'),
            ImportColumn::make('zmm_type'),
            ImportColumn::make('zmm_usp'),
            ImportColumn::make('zmm_operating_range'),
            ImportColumn::make('zmm_intake_air'),
            ImportColumn::make('zmm_oxygen_transfer_rate'),
            ImportColumn::make('zmm_air_inlet_pipesize'),
            ImportColumn::make('zmm_sump_depth'),
            ImportColumn::make('zmm_poles'),
            ImportColumn::make('zmm_motor_heading'),
            ImportColumn::make('zmm_motor_speed'),
            ImportColumn::make('zqmm_qty'),
            ImportColumn::make('zmm_1'),
            ImportColumn::make('zmm_2'),
            ImportColumn::make('zmm_3'),
            ImportColumn::make('zmm_4'),
            ImportColumn::make('zmm_5'),
            ImportColumn::make('zmm_6'),
            ImportColumn::make('zmm_7'),
            ImportColumn::make('zmm_8'),
            ImportColumn::make('zmm_9'),
            ImportColumn::make('zmm_10'),
            ImportColumn::make('zmm_11'),
            ImportColumn::make('zmm_12'),
            ImportColumn::make('zmm_13'),
            ImportColumn::make('zmm_14'),
            ImportColumn::make('zmm_15'),
            ImportColumn::make('created_by'),
            ImportColumn::make('updated_by'),
        ];
    }

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

        return new ItemCharacteristic();
    }

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