<?php

namespace App\Http\Controllers\Admin\Integrations;

use App\Http\Controllers\Controller;
use App\Models\PlatformConnection;
use App\Services\Integrations\PlatformConnectionTester;
use Illuminate\Http\RedirectResponse;

class PlatformConnectionTestController extends Controller
{
    public function __invoke(PlatformConnection $connection, PlatformConnectionTester $tester): RedirectResponse
    {
        $result = $tester->test($connection->load('secureCredential'));

        return back()->with($result->ok ? 'success' : 'error', $result->message);
    }
}
