<?php

namespace Database\Seeders\Admin;

use App\Helpers\CoreApp\Traits\PermissionTrait;
use App\Models\Role\Role;
use Illuminate\Database\Seeder;

class RoleSeeder extends Seeder
{
    use PermissionTrait;

    public function run()
    {
        $input = session()->get('input');

        $roles = [
            'superadmin' => 'Super admin',
            'admin'      => 'Admin',
            'hr'         => 'HR',
            'staff'      => 'Staff',
        ];

        foreach ($roles as $key => $role) {
            Role::firstOrCreate([
                'name'       => $role,
                'slug'       => $key,
                'company_id' => @$input['company_id'] ?? 1,
                'branch_id'  => @$input['branch_id'] ?? 1,
            ], [
                'permissions' => $this->customPermissions($key),
                'status_id'   => 1,
                'app_login'   => 1,
                'web_login'   => 1,
            ]);
        }
    }
}
