<?php

namespace App\Imports;

use App\Models\Account;
use App\Models\IncentiveSetting;
use App\Models\IncentiveSlab;
use App\Models\MasterType;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithStartRow;

class IncentiveSettingImport implements ToModel, WithStartRow
{

    /**
     * @param array $row
     *
     * @return \Illuminate\Database\Eloquent\Model|null
     */
    public function model(array $row)
    {
        $account = Account::where(['code' => $row[1]])->first();
         $slab = IncentiveSlab::where(['slab_name' => $row[3]])->first();
        if (!$slab) {
            return;
            
        }
        if (!$account) {
            
            return;
        }
        $account = IncentiveSetting::updateOrCreate(
            ['account_id' => $account->id]
        );

        return $account;
    }
    public function startRow(): int
    {
        return 2;
    }

}