<?php

namespace App\Domains\Admin\Controllers;

use App\Domains\Admin\Actions\UpdateTenantContact\UpdateTenantContactAction;
use App\Domains\Admin\Actions\UpdateTenantContact\UpdateTenantContactRequest;
use App\Scopes\CommonController;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

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

        $action = new UpdateTenantContactAction(new UpdateTenantContactRequest(
            tenant: $tenant,
            email: $request->input('email'),
            emailFinance: $request->input('email_finance'),
            postcode: $request->input('postcode'),
            city: $request->input('city'),
        ));

        $response = $action->execute();

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