<?php

declare(strict_types=1);

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

/**
 * Class StatistikyPouzivatelRoleOpravneniaDatabaseSeeder
 */
class StatistikyPouzivatelRoleOpravneniaDatabaseSeeder extends Seeder
{
    /**
     *
     */
    public function run()
    {
        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,
                ]);
            }
        });
    }
}
