<?php

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;

class SuperAdminSeeder extends Seeder
{
    /**
     * List of permissions to create.
     */
    private $permissions = [
        'role-list',
        'role-create',
        'role-edit',
        'role-delete',
        'product-list',
        'product-create',
        'product-edit',
        'product-delete',
    ];

    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        // Create permissions
        foreach ($this->permissions as $permission) {
            Permission::create(['name' => $permission]);
        }

        // Create SuperAdmin role and assign all permissions
        $role = Role::create(['name' => 'SuperAdmin']);
        $role->syncPermissions(Permission::all());

        // Create SuperAdmin user and assign SuperAdmin role
        $user = User::create([
            'name' => 'SuperAdmin',
            'email' => 'super@mail.com',
            'password' => Hash::make('super'),
        ]);

        $user->assignRole($role);
    }
}
