<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;

class RoleSeeder extends Seeder
{
    public function run(): void
    {
        $permissions = [
            'view individuals',
            'create individuals',
            'edit individuals',
            'delete individuals',
            'view groups',
            'create groups',
            'edit groups',
            'delete groups',
            'view events',
            'create events',
            'edit events',
            'delete events',
            'view documents',
            'create documents',
            'edit documents',
            'delete documents',
            'view mailing lists',
            'create mailing lists',
            'edit mailing lists',
            'delete mailing lists',
            'send mailing',
            'manage settings',
            'manage tipologie',
        ];

        foreach ($permissions as $permission) {
            Permission::firstOrCreate(['name' => $permission]);
        }

        $admin = Role::firstOrCreate(['name' => 'admin']);
        $admin->syncPermissions($permissions);

        $user = Role::firstOrCreate(['name' => 'user']);
        $user->syncPermissions([
            'view individuals',
            'create individuals',
            'edit individuals',
            'view groups',
            'view events',
            'create events',
            'edit events',
            'view documents',
            'create documents',
            'edit documents',
            'view mailing lists',
            'send mailing',
        ]);
    }
}