<?php

namespace App\Imports;

use App\Models\Number;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\WithBatchInserts;
use Maatwebsite\Excel\Concerns\WithChunkReading;
use Maatwebsite\Excel\Concerns\ToModel;

class NumberImport implements ToModel, WithChunkReading
{
    protected $user_id = '';
    protected $randomNumber = '';

    function __construct($randomNumber,$user_id) {
        $this->user_id=$user_id;
        $this->randomNumber=$randomNumber;
    }


    public function model(array $row)
    {
        return new Number([
            'user_id' => $this->user_id,
            'phone' => $row[0],
            'name' => (isset($row[1]) && !empty($row[1])) ? $row[1] : null,
            'type_id' => $this->randomNumber,
            'type' => 1,
            'status' => 0,
        ]);
    }

    public function batchSize(): int
    {
        return 3000;
    }

    public function chunkSize(): int
    {
        return 3000;
    }
}
