<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Statistiky\Database\Seeders;

use Illuminate\Database\Seeder;
use Spatie\Permission\Exceptions\PermissionDoesNotExist;
use Spatie\Permission\Exceptions\RoleDoesNotExist;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;

/**
 * Class StatistikyPouzivatelRoleOpravneniaSeeder
 *
 * @package Seka\Portal\Modul\Statistiky\Database\Seeders
 */
class StatistikyPouzivatelRoleOpravneniaSeeder extends Seeder
{
    public function run(): void
    {
        collect([
            'modul.statistiky',
            'modul.statistiky.tlacit',
            'modul.statistiky.zobrazit',
        ])->each(function ($opr) {
            try {
                Permission::findByName($opr);
            } catch (PermissionDoesNotExist $exception) {
                Permission::create([
                    'name' => $opr,
                ]);
            }
        });

        collect([
            'spravca_pek',
        ])->each(function ($rola) {
            try {
                Role::findByName($rola);
            } catch (RoleDoesNotExist $exception) {
                Role::create([
                    'name' => $rola,
                ]);
            }
        });
    }
}
