<?php

namespace App\Imports;

use App\Models\Dataset\DatasetTable23;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithStartRow;

class DatasetTable23Import implements ToModel,WithStartRow
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    protected $datasetId;
protected $userId;

    public function __construct($datasetId,$userId)
    {
        $this->datasetId = $datasetId;
        $this->userId = $userId;
    }

public function startRow(): int
    {
        return 6;
    }

public function model(array $row)
    {

// cek kalau row kosong jangan insert
        if (
            $row[0] === null && 
            $row[1] === null && 
            $row[2] === null && 
            $row[3] === null && 
            $row[4] === null && 
            $row[5] === null && 
            $row[6] === null && 
            $row[7] === null &&
            $row[8] === null &&
            $row[9] === null &&
            $row[10] === null &&
            $row[11] === null &&
            $row[12] === null &&
            $row[13] === null &&
            $row[14] === null &&
            $row[15] === null &&
            $row[16] === null &&
            $row[17] === null &&
            $row[18] === null &&
            $row[19] === null &&
            $row[20] === null &&
            $row[21] === null &&
            $row[22] === null &&
            $row[23] === null &&
            $row[24] === null &&
            $row[25] === null &&
            $row[26] === null &&
            $row[27] === null &&
            $row[28] === null
        ) {
            return null; // baris kosong dilewati
        }
        return new DatasetTable23([
            'dataset_id'                => $this->datasetId,
            'created_by'                => $this->userId,
            'lokasi'                    => $row[1],
            'waktu'                     => transformDate($row[2]),
            'lat'                       => $row[3],
            'long'                      => $row[4],
            'lokasi_sampling'           => $row[5],
            'warna'                     => $row[6],
            'kecerahan'                 => $row[7],
            'kekeruhan'                 => $row[8],
            'tss'                       => $row[9],
            'sampah'                    => $row[10],
            'lapisan_minyak'            => $row[11],
            'tempratur'                 => $row[12],
            'ph'                        => $row[13],
            'salinitas'                 => $row[14],
            'do'                        => $row[15],
            'bod5'                      => $row[16],
            'cod'                       => $row[17],
            'amonia_total'              => $row[18],
            'no2n'                      => $row[19],
            'no3n'                      => $row[20],
            'po4p'                      => $row[21],
            'sianida'                   => $row[22],
            'sulfida'                   => $row[23],
            'klor'                      => $row[24],
            'minyak_bumi'               => $row[25],
            'fenol'                     => $row[26],
            'pestisida'                 => $row[27],
            'pcb'                       => $row[28],
        ]);
    }
    
}
