<?php

namespace App\Imports;

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

class DataImport implements ToModel
{
    /**
     * @param array $row
     *
     * @return \Illuminate\Database\Eloquent\Model|null
     */
    protected $sname;
    private $rows = 0;

    public function __construct($sname)
    {
        $this->sname = $sname;
    }

    public function model(array $row)
    {
        ++$this->rows;
        return new Data([
            'phone' => $row[0],
            'service' => $this->sname,
        ]);
    }

    public function getRowCount(): int
    {
        return $this->rows;
    }
}
