<?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 PortalPouzivatelRoleOpravneniaDatabaseSeeder
 */
class PortalPouzivatelRoleOpravneniaDatabaseSeeder extends Seeder
{
    /**
     *
     */
    public function run()
    {
        collect([
            'portal_sprava',
            'portal_sprava_pouzivatelia',
        ])->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,
                ]);
            }
        });
    }
}
