<?php

namespace App\Imports;

use Spatie\Permission\Models\Permission;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;

class PermissionsImport implements ToModel, WithHeadingRow
{
    public function model(array $row)
    {
        // Skip empty rows or rows missing the 'name' column
        if (!isset($row['name']) || empty(trim($row['name']))) {
            return null;
        }

        return Permission::firstOrCreate(
            ['name' => trim($row['name'])],
            ['guard_name' => 'web']
        );
    }
}