<?php

namespace Database\Seeders\Global;

use Illuminate\Database\Seeder;
use Mtc\MercuryDataModels\Permission;
use Mtc\MercuryDataModels\Role;

class ScheduledTaskPermissionSeed extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $roles = Role::query()->whereIn('name', ['mtc', 'Administrator'])->get();

        /** @var Permission $permission */
        $permission = Permission::query()
            ->updateOrCreate([
                'name' => 'manage-scheduled-tasks',
                'guard_name' => 'web',
            ]);

        $roles->each(fn (Role $role) => $role->givePermissionTo([$permission]));
    }
}
