<?php

namespace Database\Seeders;

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

class RolePermissionSeeder extends Seeder
{
    public function run(): void
    {
        $permissions = [
            'access-admin-panel',
            'players.manage',
            'bans.manage',
            'warnings.manage',
            'whitelist.manage',
            'jobs.manage',
            'vehicles.manage',
            'items.manage',
            'economy.manage',
            'news.manage',
            'roulette.manage',
            'settings.manage',
            'logs.view',
        ];

        foreach ($permissions as $permission) {
            Permission::findOrCreate($permission, 'web');
        }

        Role::findOrCreate('player', 'web');

        $moderator = Role::findOrCreate('moderator', 'web');
        $moderator->syncPermissions([
            'access-admin-panel',
            'bans.manage',
            'warnings.manage',
            'whitelist.manage',
            'logs.view',
        ]);

        $admin = Role::findOrCreate('admin', 'web');
        $admin->syncPermissions([
            'access-admin-panel',
            'players.manage',
            'bans.manage',
            'warnings.manage',
            'whitelist.manage',
            'jobs.manage',
            'vehicles.manage',
            'items.manage',
            'economy.manage',
            'news.manage',
            'roulette.manage',
            'logs.view',
        ]);

        $superadmin = Role::findOrCreate('superadmin', 'web');
        $superadmin->syncPermissions(Permission::all());
    }
}
