<?php

namespace App\Imports;

use App\Models\Category;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Illuminate\Support\Str;

class CategoryImport implements ToModel, WithHeadingRow
{
    public function model(array $row)
    {
        if (empty($row['name'])) {
            return null;
        }

        return new Category([
            'name'        => $row['name'],
            'name_ar'     => $row['name_ar'] ?? null,
            'description' => $row['description'] ?? null,
            'color'       => $row['color'] ?? '#0d6efd',
            'is_active'   => isset($row['is_active']) ? (bool)$row['is_active'] : true,
            'slug'        => Str::slug($row['name']),
        ]);
    }
}
