<?php

namespace App\Imports;

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

class DatasetTable30Import 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
             ) {
            return null; // baris kosong dilewati
        }
        return new DatasetTable30([
            'dataset_id'                => $this->datasetId,
            'created_by'                => $this->userId,
            'nama'                      => $row[1],
            'lokasi'                    => $row[2],
            'waktu_sampling'            => $row[3],
            'lat'                       => $row[4],
            'long'                      => $row[5],
            'temperatur'                => $row[6],
            'residu_terlarut'           => $row[7],
            'residu_tersuspensi'        => $row[8],
            'ph'                        => $row[9],
            'dhl'                       => $row[10],
            'tds'                       => $row[11],
            'tss'                       => $row[12],
            'do'                        => $row[13],
            'bod'                       => $row[14],
            'cod'                       => $row[15],
            'no2'                       => $row[16],
            'no3'                       => $row[17],
            'nh3'                       => $row[18],
            'klorin_bebas'              => $row[19],
            'tp'                        => $row[20],
            'fenol'                     => $row[21],
            'minyak_lemak'              => $row[22],
            'detergen'                  => $row[23],
            'fecal_coliform'            => $row[24],
            'total_coliform'            => $row[25],
            'sianida'                   => $row[26],
            'h2s'                       => $row[27],
        ]);
    }
}
