<?php

namespace Modules\Main\Http\Controllers\Company;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Modules\Main\Models\Company\CompanyAdmin;
use Modules\Main\Models\Agent\Agent;
use App\Models\User;

class RestoreAgentController extends Controller
{
    public function __invoke(Request $request, Agent $agent)
    {
        if ($request->user()->cannot('update', $agent->company))
        {
            abort(403, 'Unauthorized action');
        }
        if ($agent->trashed())
        {
            $agent->restore();
        }
        return to_route('company.agents.table');
    }
}
