<?php

namespace App\Domains\Admin\Controllers;

use App\Models\Tenant;
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 = Tenant::where('slug', $slug)->firstOrFail();

        $tenant->update([
            'email' => $request->input('email'),
            'email_finance' => $request->input('email_finance'),
            'postcode' => $request->input('postcode'),
            'city' => $request->input('city'),
        ]);

        return response()->json([
            'status' => 'success',
            'message' => 'Kontaktdaten wurden gespeichert.',
        ]);
    }
}
