<?php

namespace App\Imports;
use App\Model\product\CategoryModel;
use Maatwebsite\Excel\Concerns\SkipsOnFailure;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Validators\Failure;
use Maatwebsite\Excel\Concerns\WithCalculatedFormulas;
use phpDocumentor\Reflection\Type;

class CategoryImport implements ToModel, WithHeadingRow, SkipsOnFailure, WithCalculatedFormulas
{

    public function model(array $row)
    {

        if (@$row['category_name']) {
            $arr = [ 'category_name' => $row['category_name'],'type' => $row['type']];
            $check = CategoryModel::where($arr)->first();
            if(!$check){
                return CategoryModel::updateOrCreate(
                    $arr,array_merge($arr,[ 'note' => $row['note']])
                );
            }
        }
    }

    public function onFailure(Failure ...$failures)
    {
        // TODO: Implement onFailure() method.
    }
}
