<?php

namespace App\Imports;

use App\Models\Proveedor;
use Maatwebsite\Excel\Concerns\ToModel;

class ProvidersImport implements ToModel
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function model(array $row)
    {
        if (!isset($row[0]) || $row[0]=='nombre') {
            return null;
        }

        if (Proveedor::where('cuit', $row[1])->exists()) {
            return null;   
        }
        return new Proveedor([
            'name'        => $row[0],
            'cuit'        => $row[1],
            'iibb'        => $row[2],
            'email'       => $row[3], 
            'address'     => $row[4], 
            'location'    => $row[5], 
            'province'    => $row[6], 
            'web'         => $row[7], 
            'phone'       => $row[8], 
            'contact'     => $row[9]
        ]);
    }
    
}
