<?php

namespace App\Domains\Permission\Commands;

use Illuminate\Console\Command;
use App\Domains\Permission\Services\RoleService;

class RoleSyncPermissionCommand extends Command
{
    protected $signature = 'role:sync-permission
            {roleId : The role id}
            {permissions : The permission ids}';

    protected $description = '角色分配权限';

    public function handle()
    {
        $roleId = $this->argument('roleId');
        $permissions = $this->argument('permissions');

        $permissions = str_to_array($permissions);

        try {
            app(RoleService::class)->syncPermissions($roleId, $permissions);
        } catch (\Exception $e) {
            $this->error('sync fail #:'. $e->getMessage());
            return;
        }

        $this->info('sync success.');
    }
}
