<?php

declare(strict_types=1);

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 PortalPouzivatelRoleOpravneniaDatabaseSeeder
 */
class PortalPouzivatelRoleOpravneniaDatabaseSeeder extends Seeder
{
    /**
     *
     */
    public function run()
    {
        collect([
            'portal_sprava',
            'portal_sprava_pouzivatelia',
            'portal_sprava_informacie',
        ])->each(function ($opr) {
            try {
                Permission::findByName($opr);
            } catch (PermissionDoesNotExist $exception) {
                Permission::create([
                    'name' => $opr,
                ]);
            }
        });

        collect([
            'supervizor',
            'admin',
            'spravca_pek',
            'technik',
            'technicka_podpora_pts',
            'kalibrator',
            'pek_konatel',
            'pek_poverena_osoba',
        ])->each(function ($rola) {
            try {
                Role::findByName($rola);
            } catch (RoleDoesNotExist $exception) {
                Role::create([
                    'name' => $rola,
                ]);
            }
        });
    }
}
