<?php

namespace App\Domains\Admin\Controllers;

use App\Domains\Admin\Actions\UpdateTenantPayment\UpdateTenantPaymentAction;
use App\Domains\Admin\Actions\UpdateTenantPayment\UpdateTenantPaymentRequest;
use App\Scopes\CommonController;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ManagedTenantPaymentUpdateController extends CommonController
{
    public function __invoke(string $slug, Request $request): JsonResponse
    {
        $tenant = $this->adminTenants->findBySlug($slug);

        $action = new UpdateTenantPaymentAction(new UpdateTenantPaymentRequest(
            tenant: $tenant,
            accountIban: $request->input('account_iban'),
            accountBic: $request->input('account_bic'),
            accountName: $request->input('account_name'),
        ));

        $response = $action->execute();

        return response()->json([
            'status' => $response->success ? 'success' : 'error',
            'message' => $response->message,
        ]);
    }
}
